Class LateralTCPListener<K,V>
java.lang.Object
org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.LateralTCPListener<K,V>
- All Implemented Interfaces:
ILateralCacheListener<K,
,V> ICacheListener<K,
,V> IShutdownObserver
public class LateralTCPListener<K,V>
extends Object
implements ILateralCacheListener<K,V>, IShutdownObserver
Listens for connections from other TCP lateral caches and handles them. The initialization method
starts a listening thread, which creates a socket server. When messages are received they are
passed to a pooled executor which then calls the appropriate handle method.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Deprecated.No longer usedclass
Deprecated.No longer used -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Deprecated.Specify serializerprotected
LateralTCPListener
(ITCPLateralCacheAttributes ilca, IElementSerializer serializer) Only need one since it does work for all regions, just reference by multiple region names. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose this listenerprotected CompositeCache<K,
V> Gets the cacheManager attribute of the LateralCacheTCPListener object.int
static <K,
V> LateralTCPListener<K, V> getInstance
(ITCPLateralCacheAttributes ilca, ICompositeCacheManager cacheMgr) Deprecated.Specify serializerstatic <K,
V> LateralTCPListener<K, V> getInstance
(ITCPLateralCacheAttributes ilca, ICompositeCacheManager cacheMgr, IElementSerializer serializer) Gets the instance attribute of the LateralCacheTCPListener class.long
Gets the listenerId attribute of the LateralCacheTCPListener objectint
This is roughly the number of updates the lateral has received.int
void
handleDispose
(String cacheName) This marks this instance as terminated.Gets the cache that was injected by the lateral factory.handleGetKeySet
(String cacheName) Gets the cache that was injected by the lateral factory.Map<K,
ICacheElement<K, V>> handleGetMatching
(String cacheName, String pattern) Gets the cache that was injected by the lateral factory.void
handlePut
(ICacheElement<K, V> element) Increments the put count.void
handleRemove
(String cacheName, K key) Increments the remove count.void
handleRemoveAll
(String cacheName) Gets the cache that was injected by the lateral factory.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) void
shutdown()
Shuts down the receiver.
-
Constructor Details
-
LateralTCPListener
Deprecated.Specify serializerOnly need one since it does work for all regions, just reference by multiple region names.- Parameters:
ilca
- ITCPLateralCacheAttributes
-
LateralTCPListener
Only need one since it does work for all regions, just reference by multiple region names.- Parameters:
ilca
- ITCPLateralCacheAttributesserializer
- the serializer to use when receiving
-
-
Method Details
-
getInstance
@Deprecated public static <K,V> LateralTCPListener<K,V> getInstance(ITCPLateralCacheAttributes ilca, ICompositeCacheManager cacheMgr) Deprecated.Specify serializerGets the instance attribute of the LateralCacheTCPListener class.- Parameters:
ilca
- ITCPLateralCacheAttributescacheMgr
-- Returns:
- The instance value
-
getInstance
public static <K,V> LateralTCPListener<K,V> getInstance(ITCPLateralCacheAttributes ilca, ICompositeCacheManager cacheMgr, IElementSerializer serializer) Gets the instance attribute of the LateralCacheTCPListener class.- Parameters:
ilca
- ITCPLateralCacheAttributescacheMgr
-serializer
- the serializer to use when receiving- Returns:
- The instance value
-
init
This starts the ListenerThread on the specified port.- Specified by:
init
in interfaceILateralCacheListener<K,
V>
-
setListenerId
Let the lateral 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.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 interfaceICacheListener<K,
V> - Parameters:
id
- The new listenerId value- Throws:
IOException
-
getListenerId
Gets the listenerId attribute of the LateralCacheTCPListener object- Specified by:
getListenerId
in interfaceICacheListener<K,
V> - Returns:
- The listenerId value
- Throws:
IOException
-
handlePut
Increments the put count. Gets the cache that was injected by the lateral factory. Calls put on the cache.- Specified by:
handlePut
in interfaceICacheListener<K,
V> - Throws:
IOException
- See Also:
-
handleRemove
Increments the remove count. Gets the cache that was injected by the lateral factory. Calls remove on the cache.- Specified by:
handleRemove
in interfaceICacheListener<K,
V> - Throws:
IOException
- See Also:
-
handleRemoveAll
Gets the cache that was injected by the lateral factory. Calls removeAll on the cache.- Specified by:
handleRemoveAll
in interfaceICacheListener<K,
V> - Throws:
IOException
- See Also:
-
handleGet
Gets the cache that was injected by the lateral factory. Calls get on the cache.- Parameters:
cacheName
-key
-- Returns:
- a ICacheElement
- Throws:
IOException
-
handleGetMatching
public Map<K,ICacheElement<K, handleGetMatchingV>> (String cacheName, String pattern) throws IOException Gets the cache that was injected by the lateral factory. Calls get on the cache.- Parameters:
cacheName
- the name of the cachepattern
- the matching pattern- Returns:
- Map
- Throws:
IOException
-
handleGetKeySet
Gets the cache that was injected by the lateral factory. Calls getKeySet on the cache.- Parameters:
cacheName
- the name of the cache- Returns:
- a set of keys
- Throws:
IOException
-
handleDispose
This marks this instance as terminated.- Specified by:
handleDispose
in interfaceICacheListener<K,
V> - Throws:
IOException
- See Also:
-
dispose
Description copied from interface:ILateralCacheListener
Dispose this listener- Specified by:
dispose
in interfaceILateralCacheListener<K,
V>
-
getCache
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 manager.
- Parameters:
name
-- Returns:
- CompositeCache
-
getPutCnt
This is roughly the number of updates the lateral has received.- Returns:
- Returns the putCnt.
-
getGetCnt
- Returns:
- Returns the getCnt.
-
getRemoveCnt
- Returns:
- Returns the removeCnt.
-
setCacheManager
- Specified by:
setCacheManager
in interfaceILateralCacheListener<K,
V> - Parameters:
cacheMgr
- The cacheMgr to set.
-
getCacheManager
- Specified by:
getCacheManager
in interfaceILateralCacheListener<K,
V> - Returns:
- Returns the cacheMgr.
-
setTcpLateralCacheAttributes
- Parameters:
tcpLateralCacheAttributes
- The tcpLateralCacheAttributes to set.
-
getTcpLateralCacheAttributes
- Returns:
- Returns the tcpLateralCacheAttributes.
-
shutdown
Shuts down the receiver.- Specified by:
shutdown
in interfaceIShutdownObserver
-