Class RMISynchronousCacheReplicator
- java.lang.Object
-
- net.sf.ehcache.distribution.RMISynchronousCacheReplicator
-
- All Implemented Interfaces:
java.lang.Cloneable,CacheReplicator,CacheEventListener
- Direct Known Subclasses:
RMIAsynchronousCacheReplicator
public class RMISynchronousCacheReplicator extends java.lang.Object implements CacheReplicator
- Version:
- $Id$
- Author:
- Greg Luck
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanreplicatePutsWhether to replicate puts.protected booleanreplicatePutsViaCopyWhether a put should replicated by copy or by invalidation, (a remove).protected booleanreplicateRemovalsWhether to replicate removesprotected booleanreplicateUpdatesWhether to replicate updates.protected booleanreplicateUpdatesViaCopyWhether an update (a put) should be by copy or by invalidation, (a remove).protected StatusstatusThe status of the replicator.
-
Constructor Summary
Constructors Constructor Description RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicatePutsViaCopy, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)Constructor for internal and subclass use
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanalive()Checks that the replicator is isSTATUS_ALIVE.java.lang.Objectclone()Creates a clone of this listener.voiddispose()Give the replicator a chance to cleanup and free resources when no longer neededbooleanisReplicateUpdatesViaCopy()Returns whether update is through copy or invalidatebooleannotAlive()Asserts that the replicator is active.voidnotifyElementEvicted(Ehcache cache, Element element)Called immediately after an element is evicted from the cache.voidnotifyElementExpired(Ehcache cache, Element element)Called immediately after an element is found to be expired.voidnotifyElementPut(Ehcache cache, Element element)Called immediately after an element has been put into the cache.voidnotifyElementRemoved(Ehcache cache, Element element)Called immediately after an attempt to remove an element.voidnotifyElementUpdated(Ehcache cache, Element element)Called immediately after an element has been put into the cache and the element already existed in the cache.voidnotifyRemoveAll(Ehcache cache)Called duringEhcache.removeAll()to indicate that the all elements have been removed from the cache in a bulk operation.protected static voidreplicatePutNotification(Ehcache cache, Element element)Does the actual RMI remote call.protected static voidreplicateRemovalNotification(Ehcache cache, java.io.Serializable key)Does the actual RMI remote call.protected voidreplicateRemoveAllNotification(Ehcache cache)Does the actual RMI remote call.
-
-
-
Field Detail
-
status
protected Status status
The status of the replicator. Only replicates whenSTATUS_ALIVE
-
replicatePuts
protected final boolean replicatePuts
Whether to replicate puts.
-
replicatePutsViaCopy
protected boolean replicatePutsViaCopy
Whether a put should replicated by copy or by invalidation, (a remove).By copy is best when the entry is expensive to produce. By invalidation is best when we are really trying to force other caches to sync back to a canonical source like a database. An example of a latter usage would be a read/write cache being used in Hibernate.
This setting only has effect if
#replicateUpdatesis true.
-
replicateUpdates
protected final boolean replicateUpdates
Whether to replicate updates.
-
replicateUpdatesViaCopy
protected final boolean replicateUpdatesViaCopy
Whether an update (a put) should be by copy or by invalidation, (a remove).By copy is best when the entry is expensive to produce. By invalidation is best when we are really trying to force other caches to sync back to a canonical source like a database. An example of a latter usage would be a read/write cache being used in Hibernate.
This setting only has effect if
#replicateUpdatesis true.
-
replicateRemovals
protected final boolean replicateRemovals
Whether to replicate removes
-
-
Constructor Detail
-
RMISynchronousCacheReplicator
public RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicatePutsViaCopy, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)Constructor for internal and subclass use- Parameters:
replicatePuts-replicateUpdates-replicateUpdatesViaCopy-replicateRemovals-
-
-
Method Detail
-
notifyElementPut
public void notifyElementPut(Ehcache cache, Element element) throws CacheException
Called immediately after an element has been put into the cache. TheCache.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:
notifyElementPutin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notificationelement- the element which was just put into the cache.- Throws:
CacheException
-
replicatePutNotification
protected static void replicatePutNotification(Ehcache cache, Element element) throws RemoteCacheException
Does the actual RMI remote call.If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other peers will continue.
- Throws:
RemoteCacheException
-
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:
notifyElementUpdatedin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notificationelement- the element which was just put into the cache.- Throws:
CacheException
-
notifyElementRemoved
public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException
Called immediately after an attempt to remove an element. The remove method will block until this method returns.This notification is received regardless of whether the cache had an element matching the removal key or not. If an element was removed, the element is passed to this method, otherwise a synthetic element, with only the key set is passed in.
- Specified by:
notifyElementRemovedin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notificationelement- the element just deleted, or a synthetic element with just the key set if no element was removed.param element just deleted- Throws:
CacheException
-
replicateRemovalNotification
protected static void replicateRemovalNotification(Ehcache cache, java.io.Serializable key) throws RemoteCacheException
Does the actual RMI remote call.If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other peers will continue.
- Throws:
RemoteCacheException
-
notifyElementExpired
public final void notifyElementExpired(Ehcache cache, Element element)
Called immediately after an element is found to be expired. TheCache.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
This implementation does not propagate expiries. It does not need to do anything because the element will expire in the remote cache at the same time. If the remote peer is not configured the same way they should not be in an cache cluster.
- Specified by:
notifyElementExpiredin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notificationelement- the element that has just expiredDeadlock Warning: expiry will often come from the
DiskStoreexpiry thread. It holds a lock to the DiskStorea the time the notification is sent. If the implementation of this method calls into a synchronizedCachemethod 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.
This replicator does not propagate these events
- Specified by:
notifyElementEvictedin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notificationelement- the element that has just been evicted
-
notifyRemoveAll
public void notifyRemoveAll(Ehcache cache)
Called duringEhcache.removeAll()to indicate that the all elements have been removed from the cache in a bulk operation. The usualnotifyElementRemoved(net.sf.ehcache.Ehcache,net.sf.ehcache.Element)is not called.This notification exists because clearing a cache is a special case. It is often not practical to serially process notifications where potentially millions of elements have been bulk deleted.
- Specified by:
notifyRemoveAllin interfaceCacheEventListener- Parameters:
cache- the cache emitting the notification
-
replicateRemoveAllNotification
protected void replicateRemoveAllNotification(Ehcache cache)
Does the actual RMI remote call. If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other peers will continue.
-
isReplicateUpdatesViaCopy
public final boolean isReplicateUpdatesViaCopy()
Description copied from interface:CacheReplicatorReturns whether update is through copy or invalidate- Specified by:
isReplicateUpdatesViaCopyin interfaceCacheReplicator- Returns:
- whether update is through copy or invalidate
-
notAlive
public final boolean notAlive()
Asserts that the replicator is active.- Specified by:
notAlivein interfaceCacheReplicator- Returns:
- true if the status is not STATUS_ALIVE
-
alive
public final boolean alive()
Checks that the replicator is isSTATUS_ALIVE.- Specified by:
alivein interfaceCacheReplicator- Returns:
- true if the replicator is is
STATUS_ALIVE, else false.
-
dispose
public void dispose()
Give the replicator a chance to cleanup and free resources when no longer needed- Specified by:
disposein interfaceCacheEventListener
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionCreates 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:
clonein interfaceCacheEventListener- Overrides:
clonein classjava.lang.Object- Returns:
- a clone
- Throws:
java.lang.CloneNotSupportedException- if the listener could not be cloned.
-
-