Class TerracottaCacheEventReplication

  • All Implemented Interfaces:
    java.lang.Cloneable, CacheEventListener

    public class TerracottaCacheEventReplication
    extends java.lang.Object
    implements CacheEventListener
    Creates a wrapper for sending out cache events through the Terracotta cluster
    Version:
    $Id$
    Author:
    Geert Bevin
    • Constructor Detail

      • TerracottaCacheEventReplication

        public TerracottaCacheEventReplication()
    • Method Detail

      • notifyElementPut

        public void notifyElementPut​(Ehcache cache,
                                     Element element)
                              throws CacheException
        Called immediately after an element has been put into the cache. The Cache.put(net.sf.ehcache.Element) method will block until this method returns.

        Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.

        Specified by:
        notifyElementPut in interface CacheEventListener
        Parameters:
        cache - the cache emitting the notification
        element - the element which was just put into the cache.
        Throws:
        CacheException
      • notifyElementUpdated

        public void notifyElementUpdated​(Ehcache cache,
                                         Element element)
                                  throws CacheException
        Called immediately after an element has been put into the cache and the element already existed in the cache. This is thus an update.

        The Cache.put(net.sf.ehcache.Element) method will block until this method returns.

        Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.

        Specified by:
        notifyElementUpdated in interface CacheEventListener
        Parameters:
        cache - the cache emitting the notification
        element - the element which was just put into the cache.
        Throws:
        CacheException
      • notifyElementExpired

        public void notifyElementExpired​(Ehcache cache,
                                         Element element)
        Called immediately after an element is found to be expired. The Cache.remove(Object) method will block until this method returns.

        Elements are checked for expiry in ehcache at the following times:

        • When a get request is made
        • When an element is spooled to the diskStore in accordance with a MemoryStore eviction policy
        • In the DiskStore when the expiry thread runs, which by default is Cache.DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
        If an element is found to be expired, it is deleted and this method is notified.
        Specified by:
        notifyElementExpired in interface CacheEventListener
        Parameters:
        cache - the cache emitting the notification
        element - the element that has just expired

        Deadlock Warning: expiry will often come from the DiskStore expiry thread. It holds a lock to the DiskStorea the time the notification is sent. If the implementation of this method calls into a synchronized Cache method and that subsequently calls into DiskStore a deadlock will result. Accordingly implementers of this method should not call back into Cache.

      • notifyElementEvicted

        public void notifyElementEvicted​(Ehcache cache,
                                         Element element)
        Called immediately after an element is evicted from the cache. Evicted in this sense means evicted from one store and not moved to another, so that it exists nowhere in the local cache.

        In a sense the Element has been removed from the cache, but it is different, thus the separate notification.

        Specified by:
        notifyElementEvicted in interface CacheEventListener
        Parameters:
        cache - the cache emitting the notification
        element - the element that has just been evicted
      • clone

        public TerracottaCacheEventReplication clone()
                                              throws java.lang.CloneNotSupportedException
        Creates a clone of this listener. This method will only be called by ehcache before a cache is initialized.

        This may not be possible for listeners after they have been initialized. Implementations should throw CloneNotSupportedException if they do not support clone.

        Specified by:
        clone in interface CacheEventListener
        Overrides:
        clone in class java.lang.Object
        Returns:
        a clone
        Throws:
        java.lang.CloneNotSupportedException - if the listener could not be cloned.
      • dispose

        public void dispose()
        Give the listener a chance to cleanup and free resources when no longer needed
        Specified by:
        dispose in interface CacheEventListener