org.apache.jcs.auxiliary.remote
Class AbstractRemoteAuxiliaryCache

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

public abstract class AbstractRemoteAuxiliaryCache
extends AbstractAuxiliaryCacheEventLogging
implements IRemoteCacheClient

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

See Also:
Serialized Form

Field Summary
protected  java.lang.String cacheName
          The cacheName
 
Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
cacheEventLogger, elementSerializer, keyMatcher
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
AbstractRemoteAuxiliaryCache(IRemoteCacheAttributes cattr, IRemoteCacheService remote, IRemoteCacheListener listener)
          Creates the base.
 
Method Summary
 void fixCache(IRemoteCacheService restoredRemote)
          Replaces the current remote cache service handle with the given handle.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          This returns the generic attributes for an auxiliary cache.
 java.lang.String getCacheName()
          Gets the cacheName attribute of the RemoteCache object.
 int getCacheType()
          Gets the cacheType attribute of the RemoteCache object
 java.util.Set getGroupKeys(java.lang.String groupName)
          Returns all the keys for a group.
 IRemoteCacheListener getListener()
          Allows other member of this package to access the listerner.
 long getListenerId()
          Gets the listenerId attribute of the RemoteCacheListener object
protected  IRemoteCacheAttributes getRemoteCacheAttributes()
           
protected  IRemoteCacheListener getRemoteCacheListener()
           
protected  IRemoteCacheService getRemoteCacheService()
           
 int getSize()
          Returns the current cache size.
 IStats getStatistics()
           
 java.lang.String getStats()
          Gets the stats attribute of the RemoteCache object.
 int getStatus()
          Returns the cache status.
 ICacheElement getUsingPool(java.io.Serializable key)
          This allows gets to timeout in case of remote server machine shutdown.
protected abstract  void handleException(java.lang.Exception ex, java.lang.String msg, java.lang.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 processGet(java.io.Serializable key)
          Synchronously get from the remote cache; if failed, replace the remote handle with a zombie.
 java.util.Map processGetMatching(java.lang.String pattern)
          Calls get matching on the server.
protected  java.util.Map processGetMultiple(java.util.Set keys)
          Gets multiple items from the cache based on the given set of keys.
protected  boolean processRemove(java.io.Serializable 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 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 remoteCacheListener)
           
protected  void setRemoteCacheService(IRemoteCacheService 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 java.lang.String cacheName
The cacheName

Constructor Detail

AbstractRemoteAuxiliaryCache

public AbstractRemoteAuxiliaryCache(IRemoteCacheAttributes cattr,
                                    IRemoteCacheService remote,
                                    IRemoteCacheListener listener)
Creates the base.

Parameters:
cattr -
remote -
listener -
Method Detail

processDispose

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

Specified by:
processDispose in class AbstractAuxiliaryCacheEventLogging
Throws:
java.io.IOException

processGet

protected ICacheElement processGet(java.io.Serializable key)
                            throws java.io.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
Parameters:
key -
Returns:
ICacheElement, a wrapper around the key, value, and attributes
Throws:
java.io.IOException

getUsingPool

public ICacheElement getUsingPool(java.io.Serializable key)
                           throws java.io.IOException
This allows gets to timeout in case of remote server machine shutdown.

Parameters:
key -
Returns:
ICacheElement
Throws:
java.io.IOException

processGetMatching

public java.util.Map processGetMatching(java.lang.String pattern)
                                 throws java.io.IOException
Calls get matching on the server. Each entry in the result is unwrapped.

Specified by:
processGetMatching in class AbstractAuxiliaryCacheEventLogging
Parameters:
pattern -
Returns:
Map
Throws:
java.io.IOException

processGetMultiple

protected java.util.Map processGetMultiple(java.util.Set keys)
                                    throws java.io.IOException
Gets multiple items from the cache based on the given set of keys.

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

processRemove

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

Specified by:
processRemove in class AbstractAuxiliaryCacheEventLogging
Parameters:
key -
Returns:
boolean, whether or not the item was removed
Throws:
java.io.IOException

processRemoveAll

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

Specified by:
processRemoveAll in class AbstractAuxiliaryCacheEventLogging
Throws:
java.io.IOException

processUpdate

protected void processUpdate(ICacheElement ce)
                      throws java.io.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
Parameters:
ce -
Throws:
java.io.IOException

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String groupName)
                           throws java.rmi.RemoteException,
                                  java.io.IOException
Returns all the keys for a group.

Specified by:
getGroupKeys in interface AuxiliaryCache
Parameters:
groupName -
Returns:
Set
Throws:
java.rmi.RemoteException
java.io.IOException

getListener

public IRemoteCacheListener getListener()
Allows other member of this package to access the listerner. This is mainly needed for deregistering a listener.

Specified by:
getListener in interface IRemoteCacheClient
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
Returns:
The listenerId value

getSize

public int getSize()
Returns the current cache size.

Specified by:
getSize in interface ICache
Returns:
The size value

handleException

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

Parameters:
ex -
msg -
eventName -
Throws:
java.io.IOException

getStats

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

Specified by:
getStats in interface ICache
Returns:
The stats value

getStatistics

public IStats getStatistics()
Specified by:
getStatistics in interface AuxiliaryCache
Returns:
IStats object

getStatus

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

Specified by:
getStatus in interface ICache
Returns:
The status value

fixCache

public void fixCache(IRemoteCacheService 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
Parameters:
restoredRemote - IRemoteCacheService -- the remote server or proxy to the remote server

getCacheType

public int getCacheType()
Gets the cacheType attribute of the RemoteCache object

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

getCacheName

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

Specified by:
getCacheName in interface ICache
Returns:
The cacheName value

setRemoteCacheService

protected void setRemoteCacheService(IRemoteCacheService remote)
Parameters:
remote - the remote to set

getRemoteCacheService

protected IRemoteCacheService 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
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 remoteCacheListener)
Parameters:
remoteCacheListener - the remoteCacheListener to set

getRemoteCacheListener

protected IRemoteCacheListener getRemoteCacheListener()
Returns:
the remoteCacheListener


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.