org.apache.jcs.auxiliary.lateral.socket.tcp
Class LateralTCPListener

java.lang.Object
  extended byorg.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPListener
All Implemented Interfaces:
ICacheListener, ILateralCacheListener, java.io.Serializable

public class LateralTCPListener
extends java.lang.Object
implements ILateralCacheListener, java.io.Serializable

Listens for connections from other TCP lateral caches and handles them.

See Also:
Serialized Form

Nested Class Summary
 class LateralTCPListener.ConnectionHandler
          Separate thread run when a command comes into the LateralTCPReceiver.
 class LateralTCPListener.ListenerThread
          Processes commands from the server socket.
 
Field Summary
protected static java.util.HashMap instances
          Map of available instances, keyed by port
 
Constructor Summary
protected LateralTCPListener(ITCPLateralCacheAttributes ilca)
          Only need one since it does work for all regions, just reference by multiple region names.
 
Method Summary
protected  CompositeCache getCache(java.lang.String name)
          Gets the cacheManager attribute of the LateralCacheTCPListener object.
 ICompositeCacheManager getCacheManager()
           
static ILateralCacheListener getInstance(ITCPLateralCacheAttributes ilca, ICompositeCacheManager cacheMgr)
          Gets the instance attribute of the LateralCacheTCPListener class.
 long getListenerId()
          Gets the listenerId attribute of the LateralCacheTCPListener object
 int getPutCnt()
          This is roughly the number of updates the lateral has received.
 int getRemoveCnt()
           
 ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
           
 void handleDispose(java.lang.String cacheName)
          Notifies the subscribers for freeing up the named cache.
 java.io.Serializable handleGet(java.lang.String cacheName, java.io.Serializable key)
           
 void handlePut(ICacheElement element)
          Notifies the subscribers for a cache entry update.
 void handleRemove(java.lang.String cacheName, java.io.Serializable key)
          Notifies the subscribers for a cache entry removal.
 void handleRemoveAll(java.lang.String cacheName)
          Notifies the subscribers for a cache remove-all.
 void init()
          This starts the ListenerThread on the specified port.
 void setCacheManager(ICompositeCacheManager cacheMgr)
           
 void setListenerId(long id)
          let the lateral cache set a listener_id.
 void setTcpLateralCacheAttributes(ITCPLateralCacheAttributes tcpLateralCacheAttributes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instances

protected static final java.util.HashMap instances
Map of available instances, keyed by port

Constructor Detail

LateralTCPListener

protected LateralTCPListener(ITCPLateralCacheAttributes ilca)
Only need one since it does work for all regions, just reference by multiple region names.

Parameters:
ilca -
Method Detail

getInstance

public static ILateralCacheListener getInstance(ITCPLateralCacheAttributes ilca,
                                                ICompositeCacheManager cacheMgr)
Gets the instance attribute of the LateralCacheTCPListener class.

Parameters:
ilca - ITCPLateralCacheAttributes
cacheMgr -
Returns:
The instance value

init

public void init()
This starts the ListenerThread on the specified port.

Specified by:
init in interface ILateralCacheListener

setListenerId

public void setListenerId(long id)
                   throws java.io.IOException
let the lateral cache set a listener_id. Since there is only one listerenr 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.

By default, the listener id is the vmid.

The service should set this value. This value will never be changed by a server we connect to. It needs to be non static, for unit tests.

The service will use the value it sets in all send requests to the sender.

Specified by:
setListenerId in interface ICacheListener
Parameters:
id - The new listenerId value
Throws:
java.io.IOException

getListenerId

public long getListenerId()
                   throws java.io.IOException
Gets the listenerId attribute of the LateralCacheTCPListener object

Specified by:
getListenerId in interface ICacheListener
Returns:
The listenerId value
Throws:
java.io.IOException

handlePut

public void handlePut(ICacheElement element)
               throws java.io.IOException
Description copied from interface: ICacheListener
Notifies the subscribers for a cache entry update.

Specified by:
handlePut in interface ICacheListener
Parameters:
element -
Throws:
java.io.IOException

handleRemove

public void handleRemove(java.lang.String cacheName,
                         java.io.Serializable key)
                  throws java.io.IOException
Description copied from interface: ICacheListener
Notifies the subscribers for a cache entry removal.

Specified by:
handleRemove in interface ICacheListener
Parameters:
cacheName -
key -
Throws:
java.io.IOException

handleRemoveAll

public void handleRemoveAll(java.lang.String cacheName)
                     throws java.io.IOException
Description copied from interface: ICacheListener
Notifies the subscribers for a cache remove-all.

Specified by:
handleRemoveAll in interface ICacheListener
Parameters:
cacheName -
Throws:
java.io.IOException

handleGet

public java.io.Serializable handleGet(java.lang.String cacheName,
                                      java.io.Serializable key)
                               throws java.io.IOException
Parameters:
cacheName -
key -
Returns:
Serializable
Throws:
java.io.IOException

handleDispose

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

Specified by:
handleDispose in interface ICacheListener
Parameters:
cacheName -
Throws:
java.io.IOException

getCache

protected CompositeCache getCache(java.lang.String name)
Gets the cacheManager attribute of the LateralCacheTCPListener object.

Normally this is set by the factory. If it wasn't set the listener defaults to the expected singleton behavior of the cache amanger.

Parameters:
name -
Returns:
CompositeCache

getPutCnt

public int getPutCnt()
This is roughly the number of updates the lateral has received.

Returns:
Returns the putCnt.

getRemoveCnt

public int getRemoveCnt()
Returns:
Returns the removeCnt.

setCacheManager

public void setCacheManager(ICompositeCacheManager cacheMgr)
Specified by:
setCacheManager in interface ILateralCacheListener
Parameters:
cacheMgr - The cacheMgr to set.

getCacheManager

public ICompositeCacheManager getCacheManager()
Specified by:
getCacheManager in interface ILateralCacheListener
Returns:
Returns the cacheMgr.

setTcpLateralCacheAttributes

public void setTcpLateralCacheAttributes(ITCPLateralCacheAttributes tcpLateralCacheAttributes)
Parameters:
tcpLateralCacheAttributes - The tcpLateralCacheAttributes to set.

getTcpLateralCacheAttributes

public ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
Returns:
Returns the tcpLateralCacheAttributes.


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