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

java.lang.Object
  extended by org.apache.jcs.auxiliary.AbstractAuxiliaryCache<K,V>
      extended by org.apache.jcs.auxiliary.remote.RemoteCacheNoWait<K,V>
All Implemented Interfaces:
AuxiliaryCache<K,V>, ICache<K,V>, ICacheType

public class RemoteCacheNoWait<K extends Serializable,V extends Serializable>
extends AbstractAuxiliaryCache<K,V>

The RemoteCacheNoWait wraps the RemoteCacheClient. The client holds a handle on the RemoteCacheService.

Used to queue up update requests to the underlying cache. These requests will be processed in their order of arrival via the cache event queue processor.

Typically errors will be handled down stream. We only need to kill the queue if an error makes it to this level from the queue. That can only happen if the queue is damaged, since the events are Processed asynchronously.

There is no reason to create a queue on startup if the remote is not healthy.

If the remote cache encounters an error it will zombie--create a balking facade for the service. The Zombie will queue up items until the connection is restored. An alternative way to accomplish the same thing would be to stop, not destroy the queue at this level. That way items would be added to the queue and then when the connection is restored, we could start the worker threads again. This is a better long term solution, but it requires some significant changes to the complicated worker queues.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.jcs.engine.behavior.ICacheType
ICacheType.CacheType
 
Field Summary
 
Fields inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
cacheEventLogger, elementSerializer, keyMatcher
 
Constructor Summary
RemoteCacheNoWait(IRemoteCacheClient<K,V> cache)
          Constructs with the given remote cache, and fires up an event queue for asynchronous processing.
 
Method Summary
 void dispose()
          Adds a dispose request to the remote cache.
 void fixCache(ICacheServiceNonLocal<?,?> remote)
          Replaces the remote cache service handle with the given handle and reset the event queue by starting up a new instance.
 ICacheElement<K,V> get(K key)
          Synchronously reads from the remote cache.
 AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
          This returns the generic attributes for an auxiliary cache.
protected  ICacheEventQueue<K,V> getCacheEventQueue()
          This is for testing only.
 String getCacheName()
          Gets the cacheName attribute of the RemoteCacheNoWait object
 ICacheType.CacheType getCacheType()
          No remote invocation.
 String getEventLoggingExtraInfo()
          this won't be called since we don't do ICache logging here.
 Set<K> getGroupKeys(String groupName)
          Gets the set of keys of objects currently in the group
 Set<String> getGroupNames()
          Gets the set of group names currently in the cache
 Map<K,ICacheElement<K,V>> getMatching(String pattern)
          Gets items from the cache matching the given pattern.
 Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
          Gets multiple items from the cache based on the given set of keys.
protected  IRemoteCacheClient<K,V> getRemoteCache()
          This is temporary.
 int getSize()
          No remote invocation.
 IStats getStatistics()
           
 String getStats()
          Returns the statistics in String form.
 CacheStatus getStatus()
          Returns the asyn cache status.
 boolean remove(K key)
          Adds a remove request to the remote cache.
 void removeAll()
          Adds a removeAll request to the remote cache.
 void resetEventQ()
          Resets the event q by first destroying the existing one and starting up new one.
 String toString()
          Returns the stats and the cache.toString().
 void update(ICacheElement<K,V> element)
          Adds a put event to the queue.
 
Methods inherited from class org.apache.jcs.auxiliary.AbstractAuxiliaryCache
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, setCacheEventLogger, setElementSerializer, setKeyMatcher
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteCacheNoWait

public RemoteCacheNoWait(IRemoteCacheClient<K,V> cache)
Constructs with the given remote cache, and fires up an event queue for asynchronous processing.

Parameters:
cache -
Method Detail

update

public void update(ICacheElement<K,V> element)
            throws IOException
Adds a put event to the queue.

Parameters:
element -
Throws:
IOException

get

public ICacheElement<K,V> get(K key)
                                                                 throws IOException
Synchronously reads from the remote cache.

Parameters:
key -
Returns:
element from the remote cache, or null if not present
Throws:
IOException

getMatching

public Map<K,ICacheElement<K,V>> getMatching(String pattern)
                                                                                                     throws IOException
Description copied from interface: ICache
Gets items from the cache matching the given pattern. Items from memory will replace those from remote sources.

This only works with string keys. It's too expensive to do a toString on every key.

Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk cache will convert * to % and . to _

Parameters:
pattern -
Returns:
Map
Throws:
IOException

getMultiple

public Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
                                                                                                     throws IOException
Gets multiple items from the cache based on the given set of keys. Sends the getMultiple request on to the server rather than looping through the requested keys.

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

getGroupKeys

public Set<K> getGroupKeys(String groupName)
                                         throws IOException
Description copied from interface: AuxiliaryCache
Gets the set of keys of objects currently in the group

Parameters:
groupName -
Returns:
the keys for the group name
Throws:
IOException

getGroupNames

public Set<String> getGroupNames()
                          throws IOException
Description copied from interface: AuxiliaryCache
Gets the set of group names currently in the cache

Returns:
the group names
Throws:
IOException

remove

public boolean remove(K key)
               throws IOException
Adds a remove request to the remote cache.

Parameters:
key -
Returns:
if this was successful
Throws:
IOException

removeAll

public void removeAll()
               throws IOException
Adds a removeAll request to the remote cache.

Throws:
IOException

dispose

public void dispose()
Adds a dispose request to the remote cache.


getSize

public int getSize()
No remote invocation.

Returns:
The size value

getCacheType

public ICacheType.CacheType getCacheType()
No remote invocation.

Returns:
The cacheType value

getStatus

public CacheStatus getStatus()
Returns the asyn cache status. An error status indicates either the remote connection is not available, or the asyn queue has been unexpectedly destroyed. No remote invocation.

Returns:
The status value

getCacheName

public String getCacheName()
Gets the cacheName attribute of the RemoteCacheNoWait object

Returns:
The cacheName value

fixCache

public void fixCache(ICacheServiceNonLocal<?,?> remote)
Replaces the remote cache service handle with the given handle and reset the event queue by starting up a new instance.

Parameters:
remote -

resetEventQ

public void resetEventQ()
Resets the event q by first destroying the existing one and starting up new one.

There may be no good reason to kill the existing queue. We will sometimes need to set a new listener id, so we should create a new queue. We should let the old queue drain. If we were Connected to the failover, it would be best to finish sending items.


getRemoteCache

protected IRemoteCacheClient<K,V> getRemoteCache()
This is temporary. It allows the manager to get the lister.

Returns:
the instance of the remote cache client used by this object

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.

Returns:
Returns the AuxiliaryCacheAttributes.

getCacheEventQueue

protected ICacheEventQueue<K,V> getCacheEventQueue()
This is for testing only. It allows you to take a look at the event queue.

Returns:
ICacheEventQueue

toString

public String toString()
Returns the stats and the cache.toString().

(non-Javadoc)

Overrides:
toString in class Object
See Also:
Object.toString()

getStats

public String getStats()
Returns the statistics in String form.

Returns:
String

getStatistics

public IStats getStatistics()
Returns:
statistics about this communication

getEventLoggingExtraInfo

public String getEventLoggingExtraInfo()
this won't be called since we don't do ICache logging here.

Specified by:
getEventLoggingExtraInfo in class AbstractAuxiliaryCache<K extends Serializable,V extends Serializable>
Returns:
String


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