net.sf.ehcache.distribution

Class RMISynchronousCacheReplicator

public class RMISynchronousCacheReplicator extends Object implements CacheReplicator

Listens to CacheManager and Cache events and propagates those to CachePeer peers of the Cache.

Version: $Id: RMISynchronousCacheReplicator.java 191 2006-09-03 22:41:48Z gregluck $

Author: Greg Luck

Field Summary
protected booleanreplicatePuts
Whether to replicate puts.
protected booleanreplicateRemovals
Whether to replicate removes
protected booleanreplicateUpdates
Whether to replicate updates.
protected booleanreplicateUpdatesViaCopy
Whether an update (a put) should be by copy or by invalidation, (a remove).
protected Statusstatus
The status of the replicator.
Constructor Summary
RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)
Constructor for internal and subclass use
Method Summary
booleanalive()
Checks that the replicator is is STATUS_ALIVE.
Objectclone()
Creates a clone of this listener.
voiddispose()
Give the replicator a chance to cleanup and free resources when no longer needed
booleanisReplicateUpdatesViaCopy()
static ListlistRemoteCachePeers(Ehcache cache)
Package protected List of cache peers
booleannotAlive()
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)
{@inheritDoc }

This implementation does not propagate expiries.

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 during removeAll to indicate that the all elements have been removed from the cache in a bulk operation.

Field Detail

replicatePuts

protected final boolean replicatePuts
Whether to replicate puts.

replicateRemovals

protected final boolean replicateRemovals
Whether to replicate removes

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

status

protected Status status
The status of the replicator. Only replicates when STATUS_ALIVE

Constructor Detail

RMISynchronousCacheReplicator

public RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)
Constructor for internal and subclass use

Parameters: replicatePuts replicateUpdates replicateUpdatesViaCopy replicateRemovals

Method Detail

alive

public final boolean alive()
Checks that the replicator is is STATUS_ALIVE.

clone

public Object 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: a clone

Throws: CloneNotSupportedException if the listener could not be cloned.

dispose

public void dispose()
Give the replicator a chance to cleanup and free resources when no longer needed

isReplicateUpdatesViaCopy

public final boolean isReplicateUpdatesViaCopy()

Returns: whether update is through copy or invalidate

listRemoteCachePeers

static List listRemoteCachePeers(Ehcache cache)
Package protected List of cache peers

Parameters: cache

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

notAlive

public final boolean notAlive()
Asserts that the replicator is active.

Returns: true if the status is not STATUS_ALIVE

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

Parameters: cache the cache emitting the notification element the element that has just been evicted

notifyElementExpired

public final void notifyElementExpired(Ehcache cache, Element element)
{@inheritDoc }

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.

notifyElementPut

public void notifyElementPut(Ehcache cache, Element element)
Called immediately after an element has been put into the cache. The put 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 the cache emitting the notification element the element which was just put into the cache.

notifyElementRemoved

public void notifyElementRemoved(Ehcache cache, Element element)
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 the cache emitting the notification element the element just deleted, or a synthetic element with just the key set if no element was removed.param element just deleted

notifyElementUpdated

public void notifyElementUpdated(Ehcache cache, Element element)
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 put 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 the cache emitting the notification element the element which was just put into the cache.

notifyRemoveAll

public void notifyRemoveAll(Ehcache cache)
Called during removeAll to indicate that the all elements have been removed from the cache in a bulk operation. The usual notifyElementRemoved 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 the cache emitting the notification