org.apache.jcs.auxiliary.remote
Class AbstractRemoteAuxiliaryCache<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCache<K,V>
      extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging<K,V>
          extended by org.apache.jcs.auxiliary.remote.AbstractRemoteAuxiliaryCache<K,V>
All Implemented Interfaces:
AuxiliaryCache<K,V>, IRemoteCacheClient<K,V>, ICache<K,V>, ICacheType
Direct Known Subclasses:
RemoteCache, RemoteHttpCache

public abstract class AbstractRemoteAuxiliaryCache<K extends Serializable,V extends Serializable>
extends AbstractAuxiliaryCacheEventLogging<K,V>
implements IRemoteCacheClient<K,V>

Abstract base for remote caches. I'm trying to break out and reuse common functionality.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.jcs.engine.behavior.ICacheType
ICacheType.CacheType
 
Field Summary
protected  String cacheName
          The cacheName
 
Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
cacheEventLogger, elementSerializer, keyMatcher
 
Constructor Summary
AbstractRemoteAuxiliaryCache(IRemoteCacheAttributes cattr, ICacheServiceNonLocal<K,V> remote, IRemoteCacheListener<K,V> listener)
          Creates the base.
 
Method Summary
 void fixCache(ICacheServiceNonLocal<?,?> restoredRemote)
          Replaces the current remote cache service handle with the given handle.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          This returns the generic attributes for an auxiliary cache.
 String getCacheName()
          Gets the cacheName attribute of the RemoteCache object.
 ICacheType.CacheType getCacheType()
          Gets the cacheType attribute of the RemoteCache object
 Set<K> getGroupKeys(String groupName)
          Returns all the keys for a group.
 Set<String> getGroupNames()
          Returns all the group names for a cache.
 IRemoteCacheListener<K,V> getListener()
          Allows other member of this package to access the listener.
 long getListenerId()
          Gets the listenerId attribute of the RemoteCacheListener object
protected  IRemoteCacheAttributes getRemoteCacheAttributes()
           
protected  IRemoteCacheListener<K,V> getRemoteCacheListener()
           
protected  ICacheServiceNonLocal<K,V> getRemoteCacheService()
           
 int getSize()
          Returns the current cache size.
 IStats getStatistics()
           
 String getStats()
          Gets the stats attribute of the RemoteCache object.
 CacheStatus getStatus()
          Returns the cache status.
 ICacheElement<K,V> getUsingPool(K key)
          This allows gets to timeout in case of remote server machine shutdown.
protected abstract  void handleException(Exception ex, String msg, String eventName)
          Custom exception handling some children.
protected  void processDispose()
          Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.
protected  ICacheElement<K,V> processGet(K key)
          Synchronously get from the remote cache; if failed, replace the remote handle with a zombie.
 Map<K,ICacheElement<K,V>> processGetMatching(String pattern)
          Calls get matching on the server.
protected  Map<K,ICacheElement<K,V>> processGetMultiple(Set<K> keys)
          Gets multiple items from the cache based on the given set of keys.
protected  boolean processRemove(K key)
          Synchronously remove from the remote cache; if failed, replace the remote handle with a zombie.
protected  void processRemoveAll()
          Synchronously removeAll from the remote cache; if failed, replace the remote handle with a zombie.
protected  void processUpdate(ICacheElement<K,V> ce)
          Serializes the object and then calls update on the remote server with the byte array.
 void setListenerId(long id)
          let the remote cache set a listener_id.
protected  void setRemoteCacheAttributes(IRemoteCacheAttributes remoteCacheAttributes)
           
protected  void setRemoteCacheListener(IRemoteCacheListener<K,V> remoteCacheListener)
           
protected  void setRemoteCacheService(ICacheServiceNonLocal<K,V> remote)
           
 
Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCacheEventLogging
dispose, disposeWithEventLogging, get, getMatching, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, remove, removeAll, removeAllWithEventLogging, removeWithEventLogging, update, updateWithEventLogging
 
Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getEventLoggingExtraInfo, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcher
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jcs.auxiliary.AuxiliaryCache
setCacheEventLogger, setElementSerializer
 
Methods inherited from interface org.apache.jcs.engine.behavior.ICache
dispose, get, getMatching, getMultiple, remove, removeAll, setKeyMatcher, update
 

Field Detail

cacheName

protected final String cacheName
The cacheName

Constructor Detail

AbstractRemoteAuxiliaryCache

public AbstractRemoteAuxiliaryCache(IRemoteCacheAttributes cattr,
                                    ICacheServiceNonLocal<K,V> remote,
                                    IRemoteCacheListener<K,V> listener)
Creates the base.

Parameters:
cattr -
remote -
listener -
Method Detail

processDispose

protected void processDispose()
                       throws IOException
Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.

Specified by:
processDispose in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Throws:
IOException

processGet

protected ICacheElement<K,V> processGet(K key)
                                                                           throws IOException
Synchronously get from the remote cache; if failed, replace the remote handle with a zombie.

Use threadpool to timeout if a value is set for GetTimeoutMillis

If we are a cluster client, we need to leave the Element in its serialized form. Cluster clients cannot deserialize objects. Cluster clients get ICacheElementSerialized objects from other remote servers.

Specified by:
processGet in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
ICacheElement, a wrapper around the key, value, and attributes
Throws:
IOException

getUsingPool

public ICacheElement<K,V> getUsingPool(K key)
                                                                          throws IOException
This allows gets to timeout in case of remote server machine shutdown.

Parameters:
key -
Returns:
ICacheElement
Throws:
IOException

processGetMatching

public Map<K,ICacheElement<K,V>> processGetMatching(String pattern)
                                                                                                            throws IOException
Calls get matching on the server. Each entry in the result is unwrapped.

Specified by:
processGetMatching in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Parameters:
pattern -
Returns:
Map
Throws:
IOException

processGetMultiple

protected Map<K,ICacheElement<K,V>> processGetMultiple(Set<K> keys)
                                                                                                               throws IOException
Gets multiple items from the cache based on the given set of keys.

Specified by:
processGetMultiple in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Parameters:
keys -
Returns:
a map of K key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
Throws:
IOException

processRemove

protected boolean processRemove(K key)
                         throws IOException
Synchronously remove from the remote cache; if failed, replace the remote handle with a zombie.

Specified by:
processRemove in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
boolean, whether or not the item was removed
Throws:
IOException

processRemoveAll

protected void processRemoveAll()
                         throws IOException
Synchronously removeAll from the remote cache; if failed, replace the remote handle with a zombie.

Specified by:
processRemoveAll in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Throws:
IOException

processUpdate

protected void processUpdate(ICacheElement<K,V> ce)
                      throws IOException
Serializes the object and then calls update on the remote server with the byte array. The byte array is wrapped in a ICacheElementSerialized. This allows the remote server to operate without any knowledge of caches classes.

Specified by:
processUpdate in class AbstractAuxiliaryCacheEventLogging<K extends Serializable,V extends Serializable>
Parameters:
ce -
Throws:
IOException

getGroupKeys

public Set<K> getGroupKeys(String groupName)
                                         throws RemoteException,
                                                IOException
Returns all the keys for a group.

Specified by:
getGroupKeys in interface AuxiliaryCache<K extends Serializable,V extends Serializable>
Parameters:
groupName -
Returns:
Set
Throws:
RemoteException
IOException

getGroupNames

public Set<String> getGroupNames()
                          throws RemoteException,
                                 IOException
Returns all the group names for a cache.

Specified by:
getGroupNames in interface AuxiliaryCache<K extends Serializable,V extends Serializable>
Returns:
Set
Throws:
RemoteException
IOException

getListener

public IRemoteCacheListener<K,V> getListener()
Allows other member of this package to access the listener. This is mainly needed for deregistering a listener.

Specified by:
getListener in interface IRemoteCacheClient<K extends Serializable,V extends Serializable>
Returns:
IRemoteCacheListener, the listener for this remote server

setListenerId

public void setListenerId(long id)
let the remote cache set a listener_id. Since there is only one listener for all the regions and every region gets registered? the id shouldn't be set if it isn't zero. If it is we assume that it is a reconnect.

Parameters:
id - The new listenerId value

getListenerId

public long getListenerId()
Gets the listenerId attribute of the RemoteCacheListener object

Specified by:
getListenerId in interface IRemoteCacheClient<K extends Serializable,V extends Serializable>
Returns:
The listenerId value

getSize

public int getSize()
Returns the current cache size.

Specified by:
getSize in interface ICache<K extends Serializable,V extends Serializable>
Returns:
The size value

handleException

protected abstract void handleException(Exception ex,
                                        String msg,
                                        String eventName)
                                 throws IOException
Custom exception handling some children. This should be used to initiate failover.

Parameters:
ex -
msg -
eventName -
Throws:
IOException

getStats

public String getStats()
Gets the stats attribute of the RemoteCache object.

Specified by:
getStats in interface ICache<K extends Serializable,V extends Serializable>
Returns:
The stats value

getStatistics

public IStats getStatistics()
Specified by:
getStatistics in interface AuxiliaryCache<K extends Serializable,V extends Serializable>
Returns:
IStats object

getStatus

public CacheStatus getStatus()
Returns the cache status. An error status indicates the remote connection is not available.

Specified by:
getStatus in interface ICache<K extends Serializable,V extends Serializable>
Returns:
The status value

fixCache

public void fixCache(ICacheServiceNonLocal<?,?> restoredRemote)
Replaces the current remote cache service handle with the given handle. If the current remote is a Zombie, then it propagates any events that are queued to the restored service.

Specified by:
fixCache in interface IRemoteCacheClient<K extends Serializable,V extends Serializable>
Parameters:
restoredRemote - ICacheServiceNonLocal -- the remote server or proxy to the remote server

getCacheType

public ICacheType.CacheType getCacheType()
Gets the cacheType attribute of the RemoteCache object

Specified by:
getCacheType in interface ICacheType
Returns:
The cacheType value

getCacheName

public String getCacheName()
Gets the cacheName attribute of the RemoteCache object.

Specified by:
getCacheName in interface ICache<K extends Serializable,V extends Serializable>
Returns:
The cacheName value

setRemoteCacheService

protected void setRemoteCacheService(ICacheServiceNonLocal<K,V> remote)
Parameters:
remote - the remote to set

getRemoteCacheService

protected ICacheServiceNonLocal<K,V> getRemoteCacheService()
Returns:
the remote

getAuxiliaryCacheAttributes

public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
Description copied from interface: AuxiliaryCache
This returns the generic attributes for an auxiliary cache. Most implementations will cast this to a more specific type.

Specified by:
getAuxiliaryCacheAttributes in interface AuxiliaryCache<K extends Serializable,V extends Serializable>
Returns:
Returns the AuxiliaryCacheAttributes.

setRemoteCacheAttributes

protected void setRemoteCacheAttributes(IRemoteCacheAttributes remoteCacheAttributes)
Parameters:
remoteCacheAttributes - the remoteCacheAttributes to set

getRemoteCacheAttributes

protected IRemoteCacheAttributes getRemoteCacheAttributes()
Returns:
the remoteCacheAttributes

setRemoteCacheListener

protected void setRemoteCacheListener(IRemoteCacheListener<K,V> remoteCacheListener)
Parameters:
remoteCacheListener - the remoteCacheListener to set

getRemoteCacheListener

protected IRemoteCacheListener<K,V> getRemoteCacheListener()
Returns:
the remoteCacheListener


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.