Class AbstractRemoteAuxiliaryCache<K,V>
java.lang.Object
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCache<K,V>
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging<K,V>
org.apache.commons.jcs3.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,V>
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.commons.jcs3.engine.behavior.ICacheType
ICacheType.CacheType
-
Field Summary
FieldsFields inherited from interface org.apache.commons.jcs3.engine.behavior.ICache
NAME_COMPONENT_DELIMITER
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractRemoteAuxiliaryCache
(IRemoteCacheAttributes cattr, ICacheServiceNonLocal<K, V> remote, IRemoteCacheListener<K, V> listener) Creates the base. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fixCache
(ICacheServiceNonLocal<?, ?> restoredRemote) Replaces the current remote cache service handle with the given handle.This returns the generic attributes for an auxiliary cache.Gets the cacheName attribute of the RemoteCache object.Gets the cacheType attribute of the RemoteCache objectReturn the keys in this cache.Allows other member of this package to access the listener.long
Gets the listenerId attribute of the RemoteCacheListener objectprotected IRemoteCacheAttributes
protected IRemoteCacheListener<K,
V> protected ICacheServiceNonLocal<K,
V> int
getSize()
Returns the current cache size.getStats()
Gets the stats attribute of the RemoteCache object.Returns the cache status.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
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 boolean
processRemove
(K key) Synchronously remove from the remote cache; if failed, replace the remote handle with a zombie.protected void
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.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging
dispose, disposeWithEventLogging, get, getMatching, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, remove, removeAll, removeAllWithEventLogging, removeWithEventLogging, update, updateWithEventLogging
Methods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCache
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getEventLoggingExtraInfo, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, processGetMultiple, 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.commons.jcs3.auxiliary.AuxiliaryCache
setCacheEventLogger, setElementSerializer
Methods inherited from interface org.apache.commons.jcs3.engine.behavior.ICache
dispose, get, getMatching, getMultiple, remove, removeAll, setKeyMatcher, update
-
Field Details
-
cacheName
The cacheName
-
-
Constructor Details
-
AbstractRemoteAuxiliaryCache
public AbstractRemoteAuxiliaryCache(IRemoteCacheAttributes cattr, ICacheServiceNonLocal<K, V> remote, IRemoteCacheListener<K, V> listener) Creates the base.- Parameters:
cattr
-remote
-listener
-
-
-
Method Details
-
processDispose
Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.- Specified by:
processDispose
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Throws:
IOException
-
processGet
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 classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
key
-- Returns:
- ICacheElement, a wrapper around the key, value, and attributes
- Throws:
IOException
-
getUsingPool
This allows gets to timeout in case of remote server machine shutdown.- Parameters:
key
-- Returns:
- ICacheElement
- Throws:
IOException
-
processGetMatching
Calls get matching on the server. Each entry in the result is unwrapped.- Specified by:
processGetMatching
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
pattern
-- Returns:
- Map
- Throws:
IOException
-
processRemove
Synchronously remove from the remote cache; if failed, replace the remote handle with a zombie.- Specified by:
processRemove
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
key
-- Returns:
- boolean, whether or not the item was removed
- Throws:
IOException
-
processRemoveAll
Synchronously removeAll from the remote cache; if failed, replace the remote handle with a zombie.- Specified by:
processRemoveAll
in classAbstractAuxiliaryCacheEventLogging<K,
V> - Throws:
IOException
-
processUpdate
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 classAbstractAuxiliaryCacheEventLogging<K,
V> - Parameters:
ce
-- Throws:
IOException
-
getKeySet
Return the keys in this cache.- Specified by:
getKeySet
in interfaceAuxiliaryCache<K,
V> - Returns:
- a set of the key type TODO This should probably be done in chunks with a range passed in. This will be a problem if someone puts a 1,000,000 or so items in a region.
- Throws:
IOException
- if access to the auxiliary cache fails- See Also:
-
getListener
Allows other member of this package to access the listener. This is mainly needed for deregistering a listener.- Specified by:
getListener
in interfaceIRemoteCacheClient<K,
V> - Returns:
- IRemoteCacheListener, the listener for this remote server
-
setListenerId
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
Gets the listenerId attribute of the RemoteCacheListener object- Specified by:
getListenerId
in interfaceIRemoteCacheClient<K,
V> - Returns:
- The listenerId value
-
getSize
Returns the current cache size. -
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
Gets the stats attribute of the RemoteCache object. -
getStatistics
- Specified by:
getStatistics
in interfaceAuxiliaryCache<K,
V> - Returns:
- IStats object
-
getStatus
Returns the cache status. An error status indicates the remote connection is not available. -
fixCache
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 interfaceIRemoteCacheClient<K,
V> - Parameters:
restoredRemote
- ICacheServiceNonLocal -- the remote server or proxy to the remote server
-
getCacheType
Gets the cacheType attribute of the RemoteCache object- Specified by:
getCacheType
in interfaceICacheType
- Returns:
- The cacheType value
-
getCacheName
Gets the cacheName attribute of the RemoteCache object.- Specified by:
getCacheName
in interfaceICache<K,
V> - Returns:
- The cacheName value
-
setRemoteCacheService
- Parameters:
remote
- the remote to set
-
getRemoteCacheService
- Returns:
- the remote
-
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 interfaceAuxiliaryCache<K,
V> - Returns:
- Returns the AuxiliaryCacheAttributes.
-
setRemoteCacheAttributes
- Parameters:
remoteCacheAttributes
- the remoteCacheAttributes to set
-
getRemoteCacheAttributes
- Returns:
- the remoteCacheAttributes
-
setRemoteCacheListener
- Parameters:
remoteCacheListener
- the remoteCacheListener to set
-
getRemoteCacheListener
- Returns:
- the remoteCacheListener
-