ehcache

net.sf.ehcache.distribution
Class RMISynchronousCacheReplicator

java.lang.Object
  extended by net.sf.ehcache.distribution.RMISynchronousCacheReplicator
All Implemented Interfaces:
CacheReplicator, CacheEventListener
Direct Known Subclasses:
RMIAsynchronousCacheReplicator

public class RMISynchronousCacheReplicator
extends java.lang.Object
implements CacheReplicator

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

Version:
$Id: RMISynchronousCacheReplicator.java 52 2006-04-24 14:50:03Z gregluck $
Author:
Greg Luck

Field Summary
protected  boolean replicatePuts
          Whether to replicate puts.
protected  boolean replicateRemovals
          Whether to replicate removes
protected  boolean replicateUpdates
          Whether to replicate updates.
protected  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
protected RMISynchronousCacheReplicator(boolean replicatePuts, boolean replicateUpdates, boolean replicateUpdatesViaCopy, boolean replicateRemovals)
          Constructor for internal and subclass use
 
Method Summary
 boolean alive()
          Checks that the replicator is is STATUS_ALIVE.
 void dispose()
          Give the replicator a chance to cleanup and free resources when no longer needed
 boolean isReplicateUpdatesViaCopy()
          Returns whether update is through copy or invalidate
(package private) static java.util.List listRemoteCachePeers(Cache cache)
          Package protected List of cache peers
 boolean notAlive()
          Asserts that the replicator is active.
 void notifyElementExpired(Cache cache, Element element)
          Called immediately after an element is found to be expired.
 void notifyElementPut(Cache cache, Element element)
          Called immediately after an element has been put into the cache.
 void notifyElementRemoved(Cache cache, Element element)
          Called immediately after an element has been removed.
 void notifyElementUpdated(Cache cache, Element element)
          Called immediately after an element has been put into the cache and the element already existed in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

status

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


replicatePuts

protected final boolean replicatePuts
Whether to replicate puts.


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.


replicateRemovals

protected final boolean replicateRemovals
Whether to replicate removes

Constructor Detail

RMISynchronousCacheReplicator

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

Parameters:
replicatePuts -
replicateUpdates -
replicateUpdatesViaCopy -
replicateRemovals -
Method Detail

notifyElementPut

public void notifyElementPut(Cache 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(Cache 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

notifyElementRemoved

public void notifyElementRemoved(Cache cache,
                                 Element element)
                          throws CacheException
Called immediately after an element has been removed. The remove method will block until this method returns.

Ehcache does not check for

As the Element has been removed, only what was the key of the element is known.

Specified by:
notifyElementRemoved in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - just deleted
Throws:
CacheException

listRemoteCachePeers

static java.util.List listRemoteCachePeers(Cache cache)
Package protected List of cache peers

Parameters:
cache -

notifyElementExpired

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

As the Element has been expired, only what was the key of the element is known.

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.

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.


isReplicateUpdatesViaCopy

public final boolean isReplicateUpdatesViaCopy()
Description copied from interface: CacheReplicator
Returns whether update is through copy or invalidate

Specified by:
isReplicateUpdatesViaCopy in interface CacheReplicator
Returns:
whether update is through copy or invalidate

notAlive

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

Specified by:
notAlive in interface CacheReplicator
Returns:
true if the status is not STATUS_ALIVE

alive

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

Specified by:
alive in interface CacheReplicator
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:
dispose in interface CacheEventListener

ehcache