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

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

public class LateralTCPService
extends Object
implements ILateralCacheService, ILateralCacheObserver

A lateral cache service implementation. Does not implement getGroupKey


Constructor Summary
LateralTCPService(ITCPLateralCacheAttributes lca)
          Constructor for the LateralTCPService object
 
Method Summary
 void addCacheListener(ICacheListener obj)
          Subscribes to all caches.
 void addCacheListener(String cacheName, ICacheListener 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 get(String cacheName, Serializable key)
          Returns a cache bean from the specified cache; or null if the key does not exist.
 ICacheElement get(String cacheName, Serializable key, long requesterId)
          If get is allowed, we will issues a get request.
 Set getGroupKeys(String cacheName, String group)
          Gets the set of keys of objects currently in the group throws UnsupportedOperationException
protected  long getListenerId()
           
 Map getMatching(String cacheName, String pattern)
          If allow get is true, we will issue a getmatching query.
 Map getMatching(String cacheName, String pattern, long requesterId)
          If allow get is true, we will issue a getmatching query.
 Map getMultiple(String cacheName, Set keys)
          Gets multiple items from the cache based on the given set of keys.
 Map getMultiple(String cacheName, Set 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, Serializable key)
          Uses the default listener id and calls the next remove method.
 void remove(String cacheName, Serializable key, long requesterId)
          Wraps the key in a LateralElementDescriptor.
 void removeAll(String cacheName)
          Remove all keys from the sepcified cache.
 void removeAll(String cacheName, long requesterId)
          Remove all keys from the specified cache.
 void removeCacheListener(ICacheListener obj)
          Unsubscribes from all caches.
 void removeCacheListener(String cacheName, ICacheListener obj)
          Unsubscribes from the specified cache.
protected  void setListenerId(long listernId)
           
 void setTcpLateralCacheAttributes(ITCPLateralCacheAttributes tcpLateralCacheAttributes)
           
 void update(ICacheElement item)
          Puts a cache item to the cache.
 void update(ICacheElement 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 item)
            throws IOException
Description copied from interface: ICacheService
Puts a cache item to the cache.

Specified by:
update in interface ICacheService
Parameters:
item -
Throws:
IOException

update

public void update(ICacheElement 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
Throws:
IOException
See Also:
ICacheServiceNonLocal.update(org.apache.jcs.engine.behavior.ICacheElement, long)

remove

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

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

remove

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

Specified by:
remove in interface ICacheServiceNonLocal
Throws:
IOException
See Also:
ICacheServiceNonLocal.remove(java.lang.String, java.io.Serializable, long)

release

public void release()
             throws IOException
Does nothing.

Specified by:
release in interface ICacheService
Throws:
IOException

dispose

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

Specified by:
dispose in interface ICacheService
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 get(String cacheName,
                         Serializable 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
Parameters:
cacheName -
key -
Returns:
ICacheElement if found.
Throws:
IOException

get

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

Specified by:
get in interface ICacheServiceNonLocal
Parameters:
cacheName -
key -
requesterId -
Returns:
ICacheElement if found.
Throws:
IOException

getMatching

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

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

getMatching

public Map 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
Parameters:
cacheName -
pattern -
requesterId - - our identity
Returns:
a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache matching the pattern.
Throws:
IOException

getMultiple

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

Specified by:
getMultiple in interface ICacheService
Parameters:
cacheName -
keys -
Returns:
a map of Serializable 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 getMultiple(String cacheName,
                       Set 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
Parameters:
cacheName -
keys -
requesterId -
Returns:
a map of Serializable 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 getGroupKeys(String cacheName,
                        String group)
Gets the set of keys of objects currently in the group throws UnsupportedOperationException

Specified by:
getGroupKeys in interface ICacheServiceNonLocal
Parameters:
cacheName -
group -
Returns:
Set

removeAll

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

Specified by:
removeAll in interface ICacheService
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
Parameters:
cacheName -
requesterId -
Throws:
IOException

main

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

addCacheListener

public void addCacheListener(String cacheName,
                             ICacheListener 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 void addCacheListener(ICacheListener obj)
                      throws IOException
Description copied from interface: ICacheObserver
Subscribes to all caches.

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

removeCacheListener

public void removeCacheListener(String cacheName,
                                ICacheListener 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 void removeCacheListener(ICacheListener 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-2012 Apache Software Foundation. All Rights Reserved.