Top Description Fields Constructors Methods
net.sf.ehcache.distribution

public Class RMISynchronousCacheReplicator

extends Object
implements CacheReplicator
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.distribution.CacheReplicator, net.sf.ehcache.event.CacheEventListener, java.lang.Cloneable
Known Direct Subclasses
net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator
Imports
net.sf.ehcache.CacheException, .Ehcache, .Element, .Status, java.io.Serializable, java.util.List, org.slf4j.Logger, .LoggerFactory

Listens to net.sf.ehcache.CacheManager and net.sf.ehcache.Cache events and propagates those to CachePeer peers of the Cache.
Author
Greg Luck
Version
$Id: RMISynchronousCacheReplicator.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private static final Logger
protected final boolean
replicatePuts

Whether to replicate puts.

protected boolean
replicatePutsViaCopy

Whether a put should replicated by copy or by invalidation, (a remove).

protected final boolean
replicateRemovals

Whether to replicate removes

protected final boolean
replicateUpdates

Whether to replicate updates.

protected final boolean
replicateUpdatesViaCopy

Whether an update (a put) should be by copy or by invalidation, (a remove).

protected Status
status

The status of the replicator.

Constructor Summary

AccessConstructor and Description
public
RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicatePutsViaCopy, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)

Constructor for internal and subclass use

Method Summary

Modifier and TypeMethod and Description
public final boolean
alive()

Implements net.sf.ehcache.distribution.CacheReplicator.alive.

Checks that the replicator is is STATUS_ALIVE.
public Object

Returns:

a clone
clone
()

Overrides java.lang.Object.clone.

Implements net.sf.ehcache.event.CacheEventListener.clone.

Creates a clone of this listener.
public void
dispose()

Implements net.sf.ehcache.event.CacheEventListener.dispose.

Give the replicator a chance to cleanup and free resources when no longer needed
public final boolean

Returns:

whether update is through copy or invalidate
isReplicateUpdatesViaCopy
()

Implements net.sf.ehcache.distribution.CacheReplicator.isReplicateUpdatesViaCopy.

Returns whether update is through copy or invalidate
pack-priv static List<CachePeer>

Returns:

a list of CachePeer peers for the given cache, excluding the local peer.
listRemoteCachePeers
(Ehcache cache)

Package protected List of cache peers

public final boolean

Returns:

true if the status is not STATUS_ALIVE
notAlive
()

Implements net.sf.ehcache.distribution.CacheReplicator.notAlive.

Asserts that the replicator is active.
public void
notifyElementEvicted(final Ehcache
the cache emitting the notification
cache
,
final Element
the element that has just been evicted
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementEvicted.

Called immediately after an element is evicted from the cache.
public final void
notifyElementExpired(final Ehcache
the cache emitting the notification
cache
,
final 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.

element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Called immediately after an element is found to be expired.
public void
notifyElementPut(final Ehcache
the cache emitting the notification
cache
,
final Element
the element which was just put into the cache.
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementPut.

Called immediately after an element has been put into the cache.
public void
notifyElementRemoved(final Ehcache
the cache emitting the notification
cache
,
final Element
the element just deleted, or a synthetic element with just the key set if no element was removed.param element just deleted
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementRemoved.

Called immediately after an attempt to remove an element.
public void
notifyElementUpdated(final Ehcache
the cache emitting the notification
cache
,
final Element
the element which was just put into the cache.
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementUpdated.

Called immediately after an element has been put into the cache and the element already existed in the cache.
public void
notifyRemoveAll(final Ehcache
the cache emitting the notification
cache
)

Implements net.sf.ehcache.event.CacheEventListener.notifyRemoveAll.

Called during net.sf.ehcache.Ehcache#removeAll() to indicate that the all elements have been removed from the cache in a bulk operation.
protected static void
replicatePutNotification(Ehcache cache, Element element)

Does the actual RMI remote call.

protected static void
replicateRemovalNotification(Ehcache cache, Serializable key)

Does the actual RMI remote call.

protected void
replicateRemoveAllNotification(Ehcache cache)

Does the actual RMI remote call.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG
replicatePutsback to summary
protected final boolean replicatePuts

Whether to replicate puts.

replicatePutsViaCopyback to summary
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 #replicateUpdates is true.

replicateRemovalsback to summary
protected final boolean replicateRemovals

Whether to replicate removes

replicateUpdatesback to summary
protected final boolean replicateUpdates

Whether to replicate updates.

replicateUpdatesViaCopyback to summary
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 #replicateUpdates is true.

statusback to summary
protected Status status

The status of the replicator. Only replicates when STATUS_ALIVE

Constructor Detail

RMISynchronousCacheReplicatorback to summary
public RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicatePutsViaCopy, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)

Constructor for internal and subclass use

Method Detail

aliveback to summary
public final boolean alive()

Implements net.sf.ehcache.distribution.CacheReplicator.alive.

Checks that the replicator is is STATUS_ALIVE.

Returns:boolean

Doc from net.sf.ehcache.distribution.CacheReplicator.alive.

true if the replicator is is STATUS_ALIVE, else false.

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Implements net.sf.ehcache.event.CacheEventListener.clone.

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.

Returns:Object

a clone

Exceptions
CloneNotSupportedException:
if the listener could not be cloned.
disposeback to summary
public void dispose()

Implements net.sf.ehcache.event.CacheEventListener.dispose.

Give the replicator a chance to cleanup and free resources when no longer needed

isReplicateUpdatesViaCopyback to summary
public final boolean isReplicateUpdatesViaCopy()

Implements net.sf.ehcache.distribution.CacheReplicator.isReplicateUpdatesViaCopy.

Doc from net.sf.ehcache.distribution.CacheReplicator.isReplicateUpdatesViaCopy.

Returns whether update is through copy or invalidate

Returns:boolean

whether update is through copy or invalidate

listRemoteCachePeersback to summary
pack-priv static List<CachePeer> listRemoteCachePeers(Ehcache cache)

Package protected List of cache peers

Returns:List<CachePeer>

a list of CachePeer peers for the given cache, excluding the local peer.

notAliveback to summary
public final boolean notAlive()

Implements net.sf.ehcache.distribution.CacheReplicator.notAlive.

Asserts that the replicator is active.

Returns:boolean

true if the status is not STATUS_ALIVE

notifyElementEvictedback to summary
public void notifyElementEvicted(final Ehcache cache, final Element element)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementEvicted.

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

Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element that has just been evicted

notifyElementExpiredback to summary
public final void notifyElementExpired(final Ehcache cache, final Element element)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Called immediately after an element is found to be expired. The net.sf.ehcache.Cache#remove(Object) method will block until this method returns.

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

If an element is found to be expired, it is deleted and this method is notified.

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.

Parameters
cache:Ehcache

the cache emitting the notification

element: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.

notifyElementPutback to summary
public void notifyElementPut(final Ehcache cache, final Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementPut.

Called immediately after an element has been put into the cache. The net.sf.ehcache.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.

Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element which was just put into the cache.

notifyElementRemovedback to summary
public void notifyElementRemoved(final Ehcache cache, final Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementRemoved.

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.

Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element just deleted, or a synthetic element with just the key set if no element was removed.param element just deleted

notifyElementUpdatedback to summary
public void notifyElementUpdated(final Ehcache cache, final Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementUpdated.

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 net.sf.ehcache.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.

Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element which was just put into the cache.

notifyRemoveAllback to summary
public void notifyRemoveAll(final Ehcache cache)

Implements net.sf.ehcache.event.CacheEventListener.notifyRemoveAll.

Called during net.sf.ehcache.Ehcache#removeAll() to indicate that the all elements have been removed from the cache in a bulk operation. The usual notifyElementRemoved(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.

Parameters
cache:Ehcache

the cache emitting the notification

replicatePutNotificationback to summary
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.

replicateRemovalNotificationback to summary
protected static void replicateRemovalNotification(Ehcache cache, 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.

replicateRemoveAllNotificationback to summary
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.