org.softamis.net.cache.impl
Class DefaultDistributedCache<K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.cache.impl.MapBasedCache<K,V>
      extended by org.softamis.net.cache.impl.DefaultDistributedCache<K,V>
Type Parameters:
K - type of keys used to identify cache items
V - type of values stored in the cache
All Implemented Interfaces:
SimpleCache<K,V>, RegistryEventProcessor<K,V>
Direct Known Subclasses:
DefaultDistributedCache

public class DefaultDistributedCache<K extends java.io.Serializable,V extends java.io.Serializable>
extends MapBasedCache<K,V>
implements RegistryEventProcessor<K,V>

Implementation of cache that synchronizes it's states over network. It relies on CommunicationHelper to perform necesary network communications. Also, this implementation does not handle possible collisions that could occur due to simultaneous update of cache content in varios places over network. If item under the same key is added to cache in several places, only order of underlying network notifications about changes will determine the value which will be actually stored in cache which synchronized.

Author:
Andrew Sazonov

Field Summary
protected  CommunicationHelper<K,V> fCommunicationHelper
          CommunicationHelper responsible for performing network communications
 
Fields inherited from class org.softamis.net.cache.impl.MapBasedCache
fCacheLock, fData
 
Constructor Summary
DefaultDistributedCache()
           
 
Method Summary
 void close()
          Closes ProvidingRegistry.
protected  void doAfterObjectAdded(K aKey, V aValue)
          Method called after adding object to the cache.
protected  void doAfterUpdate()
          Method called after cache updates.
protected  void doInit()
           
 CommunicationHelper<K,V> getCommunicationHelper()
          Returns communicationHelper responsible for performing network communications
 void init()
          Method that performs initialization of the registry provider by additing it as listener to CommunicationHelper used to perform network communication.
protected  void insureCommunicationHelperSet()
           
 void processItemInvalid(ItemEntry<K,V> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_INVALID notification
 void processItemRegistered(ItemEntry<K,V> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_REGISTERED notification
 void processItemsRequest(ItemEntry<K,V> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_REQUEST notification - typically will be processed by ProvidingRegistry
 void processItemUnregistered(ItemEntry<K,V> aEntry)
          Callback for processing CommunicationHelper.COMMAND_ITEM_UNREGISTERED notification
 void setCommunicationHelper(CommunicationHelper<K,V> aCommunicationHelper)
          Sets communicationHelper responsible for performing network communications
 
Methods inherited from class org.softamis.net.cache.impl.MapBasedCache
clear, getKeys, getObject, getValues, saveObject, size, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fCommunicationHelper

protected CommunicationHelper<K extends java.io.Serializable,V extends java.io.Serializable> fCommunicationHelper
CommunicationHelper responsible for performing network communications

Constructor Detail

DefaultDistributedCache

public DefaultDistributedCache()
Method Detail

doAfterUpdate

protected void doAfterUpdate()
Description copied from class: MapBasedCache
Method called after cache updates. Inherited classes may override it to implement additional processing such as issuing networking notification for synchronization.

Overrides:
doAfterUpdate in class MapBasedCache<K extends java.io.Serializable,V extends java.io.Serializable>

processItemInvalid

public void processItemInvalid(ItemEntry<K,V> aEntry)
Description copied from interface: RegistryEventProcessor
Callback for processing CommunicationHelper.COMMAND_ITEM_INVALID notification

Specified by:
processItemInvalid in interface RegistryEventProcessor<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aEntry - recevied item entry

processItemRegistered

public void processItemRegistered(ItemEntry<K,V> aEntry)
Description copied from interface: RegistryEventProcessor
Callback for processing CommunicationHelper.COMMAND_ITEM_REGISTERED notification

Specified by:
processItemRegistered in interface RegistryEventProcessor<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aEntry - recevied item entry

processItemsRequest

public void processItemsRequest(ItemEntry<K,V> aEntry)
Description copied from interface: RegistryEventProcessor
Callback for processing CommunicationHelper.COMMAND_ITEM_REQUEST notification - typically will be processed by ProvidingRegistry

Specified by:
processItemsRequest in interface RegistryEventProcessor<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aEntry - recevied item entry

processItemUnregistered

public void processItemUnregistered(ItemEntry<K,V> aEntry)
Description copied from interface: RegistryEventProcessor
Callback for processing CommunicationHelper.COMMAND_ITEM_UNREGISTERED notification

Specified by:
processItemUnregistered in interface RegistryEventProcessor<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aEntry - recevied item entry

doAfterObjectAdded

protected void doAfterObjectAdded(K aKey,
                                  V aValue)
Description copied from class: MapBasedCache
Method called after adding object to the cache. Inherited classes may override it to add futher processing of insertion of items to cache (for example, by issuing necessary network notifications)

Overrides:
doAfterObjectAdded in class MapBasedCache<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aKey - key of item
aValue - item added

insureCommunicationHelperSet

protected void insureCommunicationHelperSet()

init

public void init()
Method that performs initialization of the registry provider by additing it as listener to CommunicationHelper used to perform network communication.

NOTE: This method SHOULD be called to let provider registry to handle request for items published.


doInit

protected void doInit()

close

public void close()
Closes ProvidingRegistry. During closing, ProvidingRegistry first removes iteself from the list of listeners in CommunicationHelper (and thus stopping processing of incoming requests for items) and then issues "item unregistered" notifications for all items were published via this particular ProvidingRegistry.


getCommunicationHelper

public CommunicationHelper<K,V> getCommunicationHelper()
Returns communicationHelper responsible for performing network communications

Returns:
communicationHelper

setCommunicationHelper

public void setCommunicationHelper(CommunicationHelper<K,V> aCommunicationHelper)
Sets communicationHelper responsible for performing network communications

Parameters:
aCommunicationHelper - communicationHelper