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

java.lang.Object
  extended by org.apache.jcs.auxiliary.remote.AbstractRemoteCacheListener<K,V>
All Implemented Interfaces:
Serializable, Remote, IRemoteCacheListener<K,V>, ICacheListener<K,V>
Direct Known Subclasses:
RemoteCacheListener, RemoteHttpClientListener

public abstract class AbstractRemoteCacheListener<K extends Serializable,V extends Serializable>
extends Object
implements IRemoteCacheListener<K,V>, Serializable

Shared listener base.

See Also:
Serialized Form

Field Summary
protected  ICompositeCacheManager cacheMgr
          The cache manager used to put items in different regions.
protected  IRemoteCacheAttributes irca
          The remote cache configuration object.
protected  long listenerId
          This is set by the remote cache server.
protected  int puts
          Number of put requests received.
protected  int removes
          Number of remove requests received.
 
Fields inherited from interface org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener
CLIENT_LISTENER, SERVER_LISTENER
 
Constructor Summary
AbstractRemoteCacheListener(IRemoteCacheAttributes irca, ICompositeCacheManager cacheMgr)
          Only need one since it does work for all regions, just reference by multiple region names.
 
Method Summary
protected  ICompositeCacheManager getCacheManager()
          Gets the cacheManager attribute of the RemoteCacheListener object.
 long getListenerId()
          Gets the listenerId attribute of the RemoteCacheListener object.
 String getLocalHostAddress()
          This is for debugging.
 RemoteType getRemoteType()
          Gets the remoteType attribute of the RemoteCacheListener object
 void handleDispose(String cacheName)
          Notifies the subscribers for freeing up the named cache.
 void handlePut(ICacheElement<K,V> cb)
          If this is configured to remove on put, then remove the element since it has been updated elsewhere. cd should be incomplete for faster transmission.
 void handleRemove(String cacheName, K key)
          Calls localRemove on the CompositeCache.
 void handleRemoveAll(String cacheName)
          Calls localRemoveAll on the CompositeCache.
 void setListenerId(long id)
          Let the remote cache set a listener_id.
 String toString()
          For easier debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener
dispose
 

Field Detail

cacheMgr

protected transient ICompositeCacheManager cacheMgr
The cache manager used to put items in different regions. This is set lazily and should not be sent to the remote server.


irca

protected IRemoteCacheAttributes irca
The remote cache configuration object.


puts

protected int puts
Number of put requests received. For debugging only.


removes

protected int removes
Number of remove requests received. For debugging only.


listenerId

protected long listenerId
This is set by the remote cache server.

Constructor Detail

AbstractRemoteCacheListener

public AbstractRemoteCacheListener(IRemoteCacheAttributes irca,
                                   ICompositeCacheManager cacheMgr)
Only need one since it does work for all regions, just reference by multiple region names.

The constructor exports this object, making it available to receive incoming calls. The callback port is anonymous unless a local port value was specified in the configuration.

Parameters:
irca -
cacheMgr -
Method Detail

setListenerId

public void setListenerId(long id)
                   throws IOException
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.

Specified by:
setListenerId in interface IRemoteCacheListener<K extends Serializable,V extends Serializable>
Specified by:
setListenerId in interface ICacheListener<K extends Serializable,V extends Serializable>
Parameters:
id - The new listenerId value
Throws:
IOException

getListenerId

public long getListenerId()
                   throws IOException
Gets the listenerId attribute of the RemoteCacheListener object. This is stored in the object. The RemoteCache object contains a reference to the listener and get the id this way.

Specified by:
getListenerId in interface IRemoteCacheListener<K extends Serializable,V extends Serializable>
Specified by:
getListenerId in interface ICacheListener<K extends Serializable,V extends Serializable>
Returns:
The listenerId value
Throws:
IOException

getRemoteType

public RemoteType getRemoteType()
                         throws IOException
Gets the remoteType attribute of the RemoteCacheListener object
Specified by:
getRemoteType in interface IRemoteCacheListener<K extends Serializable,V extends Serializable>
Returns:
The remoteType value
Throws:
IOException

handlePut

public void handlePut(ICacheElement<K,V> cb)
               throws IOException
If this is configured to remove on put, then remove the element since it has been updated elsewhere. cd should be incomplete for faster transmission. We don't want to pass data only invalidation. The next time it is used the local cache will get the new version from the remote store.

If remove on put is not configured, then update the item.

Specified by:
handlePut in interface ICacheListener<K extends Serializable,V extends Serializable>
Parameters:
cb -
Throws:
IOException

handleRemove

public void handleRemove(String cacheName,
                         K key)
                  throws IOException
Calls localRemove on the CompositeCache.

Specified by:
handleRemove in interface ICacheListener<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
key -
Throws:
IOException

handleRemoveAll

public void handleRemoveAll(String cacheName)
                     throws IOException
Calls localRemoveAll on the CompositeCache.

Specified by:
handleRemoveAll in interface ICacheListener<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
Throws:
IOException

handleDispose

public void handleDispose(String cacheName)
                   throws IOException
Description copied from interface: ICacheListener
Notifies the subscribers for freeing up the named cache.

Specified by:
handleDispose in interface ICacheListener<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
Throws:
IOException

getCacheManager

protected ICompositeCacheManager getCacheManager()
Gets the cacheManager attribute of the RemoteCacheListener object. This is one of the few places that force the cache to be a singleton.


getLocalHostAddress

public String getLocalHostAddress()
                           throws IOException
This is for debugging. It allows the remote server to log the address of clients.

Specified by:
getLocalHostAddress in interface IRemoteCacheListener<K extends Serializable,V extends Serializable>
Returns:
String
Throws:
IOException

toString

public String toString()
For easier debugging.

Overrides:
toString in class Object
Returns:
Basic info on this listener.


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