org.apache.jcs.auxiliary.lateral.socket.tcp
Class LateralTCPService<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPService<K,V>
All Implemented Interfaces:
Remote, ILateralCacheObserver, ICacheObserver, ICacheService<K,V>, ICacheServiceNonLocal<K,V>

public class LateralTCPService<K extends Serializable,V extends Serializable>
extends Object
implements ICacheServiceNonLocal<K,V>, ILateralCacheObserver

A lateral cache service implementation. Does not implement getGroupKey


Constructor Summary
LateralTCPService(ITCPLateralCacheAttributes lca)
          Constructor for the LateralTCPService object
 
Method Summary
<KK extends Serializable,VV extends Serializable>
void
addCacheListener(ICacheListener<KK,VV> obj)
          Subscribes to all caches.
<KK extends Serializable,VV extends Serializable>
void
addCacheListener(String cacheName, ICacheListener<KK,VV> obj)
          Subscribes to the specified cache.
 void dispose(String cacheName)
          Will close the connection.
 Serializable get(String key)
          The service does not get via this method, so this return null.
 ICacheElement<K,V> get(String cacheName, K key)
          Returns a cache bean from the specified cache; or null if the key does not exist.
 ICacheElement<K,V> get(String cacheName, K key, long requesterId)
          If get is allowed, we will issues a get request.
 Set<K> getGroupKeys(String cacheName, String group)
          Gets the set of keys of objects currently in the group
 Set<String> getGroupNames(String cacheName)
          Gets the set of groups currently in the cache throws UnsupportedOperationException
protected  long getListenerId()
           
 Map<K,ICacheElement<K,V>> getMatching(String cacheName, String pattern)
          If allow get is true, we will issue a getmatching query.
 Map<K,ICacheElement<K,V>> getMatching(String cacheName, String pattern, long requesterId)
          If allow get is true, we will issue a getmatching query.
 Map<K,ICacheElement<K,V>> getMultiple(String cacheName, Set<K> keys)
          Gets multiple items from the cache based on the given set of keys.
 Map<K,ICacheElement<K,V>> getMultiple(String cacheName, Set<K> keys, long requesterId)
          This issues a separate get for each item.
 ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
           
static void main(String[] args)
           
 void release()
          Does nothing.
 void remove(String cacheName, K key)
          Uses the default listener id and calls the next remove method.
 void remove(String cacheName, K key, long requesterId)
          Wraps the key in a LateralElementDescriptor.
 void removeAll(String cacheName)
          Remove all keys from the specified cache.
 void removeAll(String cacheName, long requesterId)
          Remove all keys from the specified cache.
<KK extends Serializable,VV extends Serializable>
void
removeCacheListener(ICacheListener<KK,VV> obj)
          Unsubscribes from all caches.
<KK extends Serializable,VV extends Serializable>
void
removeCacheListener(String cacheName, ICacheListener<KK,VV> obj)
          Unsubscribes from the specified cache.
protected  void setListenerId(long listernId)
           
 void setTcpLateralCacheAttributes(ITCPLateralCacheAttributes tcpLateralCacheAttributes)
           
 void update(ICacheElement<K,V> item)
          Puts a cache item to the cache.
 void update(ICacheElement<K,V> item, long requesterId)
          If put is allowed, we will issue a put.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LateralTCPService

public LateralTCPService(ITCPLateralCacheAttributes lca)
                  throws IOException
Constructor for the LateralTCPService object

Parameters:
lca - ITCPLateralCacheAttributes
Throws:
IOException
Method Detail

update

public void update(ICacheElement<K,V> item)
            throws IOException
Description copied from interface: ICacheService
Puts a cache item to the cache.

Specified by:
update in interface ICacheService<K extends Serializable,V extends Serializable>
Parameters:
item -
Throws:
IOException

update

public void update(ICacheElement<K,V> item,
                   long requesterId)
            throws IOException
If put is allowed, we will issue a put. If issue put on remove is configured, we will issue a remove. Either way, we create a lateral element descriptor, which is essentially a JCS TCP packet. It describes what operation the receiver should take when it gets the packet.

Specified by:
update in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Throws:
IOException
See Also:
org.apache.jcs.auxiliary.lateral.behavior.ICacheServiceNonLocal#update(org.apache.jcs.engine.behavior.ICacheElement, long)

remove

public void remove(String cacheName,
                   K key)
            throws IOException
Uses the default listener id and calls the next remove method.

Specified by:
remove in interface ICacheService<K extends Serializable,V extends Serializable>
Throws:
IOException
See Also:
ICacheService.remove(java.lang.String, java.io.Serializable)

remove

public void remove(String cacheName,
                   K key,
                   long requesterId)
            throws IOException
Wraps the key in a LateralElementDescriptor.

Specified by:
remove in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Throws:
IOException
See Also:
org.apache.jcs.auxiliary.lateral.behavior.ICacheServiceNonLocal#remove(java.lang.String, java.io.Serializable, long)

release

public void release()
             throws IOException
Does nothing.

Specified by:
release in interface ICacheService<K extends Serializable,V extends Serializable>
Throws:
IOException

dispose

public void dispose(String cacheName)
             throws IOException
Will close the connection.

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

get

public Serializable get(String key)
                 throws IOException
The service does not get via this method, so this return null.

Parameters:
key -
Returns:
always null.
Throws:
IOException

get

public ICacheElement<K,V> get(String cacheName,
                              K key)
                                                                 throws IOException
Description copied from interface: ICacheService
Returns a cache bean from the specified cache; or null if the key does not exist.

Specified by:
get in interface ICacheService<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
key -
Returns:
ICacheElement if found.
Throws:
IOException

get

public ICacheElement<K,V> get(String cacheName,
                              K key,
                              long requesterId)
                                                                 throws IOException
If get is allowed, we will issues a get request.

Specified by:
get in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
key -
requesterId -
Returns:
ICacheElement if found.
Throws:
IOException

getMatching

public Map<K,ICacheElement<K,V>> getMatching(String cacheName,
                                             String pattern)
                                                                                                     throws IOException
If allow get is true, we will issue a getmatching query.

Specified by:
getMatching in interface ICacheService<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
pattern -
Returns:
a map of K key to ICacheElement element, or an empty map if there is no data in cache matching the pattern.
Throws:
IOException

getMatching

public Map<K,ICacheElement<K,V>> getMatching(String cacheName,
                                             String pattern,
                                             long requesterId)
                                                                                                     throws IOException
If allow get is true, we will issue a getmatching query.

Specified by:
getMatching in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
pattern -
requesterId - - our identity
Returns:
a map of K key to ICacheElement element, or an empty map if there is no data in cache matching the pattern.
Throws:
IOException

getMultiple

public Map<K,ICacheElement<K,V>> getMultiple(String cacheName,
                                             Set<K> keys)
                                                                                                     throws IOException
Gets multiple items from the cache based on the given set of keys.

Specified by:
getMultiple in interface ICacheService<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
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

getMultiple

public Map<K,ICacheElement<K,V>> getMultiple(String cacheName,
                                             Set<K> keys,
                                             long requesterId)
                                                                                                     throws IOException
This issues a separate get for each item.

TODO We should change this. It should issue one request.

Specified by:
getMultiple in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
keys -
requesterId -
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 cacheName,
                           String group)
                                         throws IOException
Gets the set of keys of objects currently in the group

Specified by:
getGroupKeys in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
group -
Returns:
Set
Throws:
IOException

getGroupNames

public Set<String> getGroupNames(String cacheName)
                          throws IOException
Gets the set of groups currently in the cache throws UnsupportedOperationException

Specified by:
getGroupNames in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
Returns:
Set
Throws:
IOException

removeAll

public void removeAll(String cacheName)
               throws IOException
Description copied from interface: ICacheService
Remove all keys from the specified cache.

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

removeAll

public void removeAll(String cacheName,
                      long requesterId)
               throws IOException
Description copied from interface: ICacheServiceNonLocal
Remove all keys from the specified cache.

Specified by:
removeAll in interface ICacheServiceNonLocal<K extends Serializable,V extends Serializable>
Parameters:
cacheName -
requesterId -
Throws:
IOException

main

public static void main(String[] args)
Parameters:
args -

addCacheListener

public <KK extends Serializable,VV extends Serializable> void addCacheListener(String cacheName,
                                                                               ICacheListener<KK,VV> obj)
                      throws IOException
Description copied from interface: ICacheObserver
Subscribes to the specified cache.

Specified by:
addCacheListener in interface ICacheObserver
Parameters:
cacheName -
obj -
Throws:
IOException

addCacheListener

public <KK extends Serializable,VV extends Serializable> void addCacheListener(ICacheListener<KK,VV> obj)
                      throws IOException
Description copied from interface: ICacheObserver
Subscribes to all caches.

Specified by:
addCacheListener in interface ICacheObserver
Parameters:
obj -
Throws:
IOException

removeCacheListener

public <KK extends Serializable,VV extends Serializable> void removeCacheListener(String cacheName,
                                                                                  ICacheListener<KK,VV> obj)
                         throws IOException
Description copied from interface: ICacheObserver
Unsubscribes from the specified cache.

Specified by:
removeCacheListener in interface ICacheObserver
Parameters:
cacheName -
obj -
Throws:
IOException

removeCacheListener

public <KK extends Serializable,VV extends Serializable> void removeCacheListener(ICacheListener<KK,VV> obj)
                         throws IOException
Description copied from interface: ICacheObserver
Unsubscribes from all caches.

Specified by:
removeCacheListener in interface ICacheObserver
Parameters:
obj -
Throws:
IOException

setListenerId

protected void setListenerId(long listernId)
Parameters:
listernId - The listernId to set.

getListenerId

protected long getListenerId()
Returns:
Returns the listernId.

setTcpLateralCacheAttributes

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

getTcpLateralCacheAttributes

public ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
Returns:
Returns the tcpLateralCacheAttributes.


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