org.apache.jcs.auxiliary.remote.server
Class RemoteCacheServer

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended byjava.rmi.server.UnicastRemoteObject
              extended byorg.apache.jcs.auxiliary.remote.server.RemoteCacheServer
All Implemented Interfaces:
ICacheObserver, ICacheService, ICacheServiceAdmin, IRemoteCacheObserver, IRemoteCacheService, IRemoteCacheServiceAdmin, java.rmi.Remote, java.io.Serializable, java.rmi.server.Unreferenced

public class RemoteCacheServer
extends java.rmi.server.UnicastRemoteObject
implements IRemoteCacheService, IRemoteCacheObserver, IRemoteCacheServiceAdmin, java.rmi.server.Unreferenced

Provides remote cache services.

Author:
asmuts
See Also:
Serialized Form

Field Summary
private  java.util.Hashtable cacheListenersMap
           
private  CompositeCacheManager cacheManager
           
 java.lang.String className
          Description of the Field
private  java.util.Hashtable clusterListenersMap
           
private  java.util.Hashtable idTypeMap
           
private  int[] listenerId
           
private static org.apache.commons.logging.Log log
           
private  int puts
           
protected  IRemoteCacheServerAttributes rcsa
          Description of the Field
protected static boolean timing
          Description of the Field
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
 
Fields inherited from class java.rmi.server.RemoteServer
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
protected RemoteCacheServer(IRemoteCacheServerAttributes rcsa)
          Constructor for the RemoteCacheServer object
 
Method Summary
 void addCacheListener(ICacheListener listener)
          Subscribes to all remote caches.
 void addCacheListener(java.lang.String cacheName, ICacheListener listener)
          Subscribes to the specified remote cache.
private static void cleanupEventQMap(java.util.Map eventQMap)
          Description of the Method
protected  CompositeCacheManager createCacheManager(java.lang.String prop)
          Subclass can overrdie this method to create the specific cache manager.
 void dispose(java.lang.String cacheName)
          Frees the specified remote cache.
 void dispose(java.lang.String cacheName, byte requesterId)
          Description of the Method
 ICacheElement get(java.lang.String cacheName, java.io.Serializable key)
          Returns a cache value from the specified remote cache; or null if the cache or key does not exist.
private  CacheListeners getCacheListeners(java.lang.String cacheName)
          Returns the cache lsitener for the specified cache.
private  CacheListeners getClusterListeners(java.lang.String cacheName)
          Gets the clusterListeners attribute of the RemoteCacheServer object
private  ICacheEventQueue[] getEventQList(CacheListeners cacheListeners, byte requesterId)
          Gets the eventQList attribute of the RemoteCacheServer object
 java.util.Set getGroupKeys(java.lang.String cacheName, java.lang.String group)
          Gets the set of keys of objects currently in the group
private  java.lang.String getRequester()
          Gets the requester attribute of the RemoteCacheServer object
 java.lang.String getStats()
          Gets the stats attribute of the RemoteCacheServer object
protected  void init(java.lang.String prop)
          RMI Cache Server.
private  byte nextListenerId()
          Returns the next generated listener id [0,255].
private static void p1(java.lang.String s)
          Description of the Method
 void put(ICacheElement item)
          Puts a cache bean to the remote cache and notifies all listeners which
have a different host than the originating host; are currently subscribed to the related cache.
 void release()
          Frees all remote caches.
 void remove(java.lang.String cacheName, java.io.Serializable key)
          Removes the given key from the specified remote cache.
 void remove(java.lang.String cacheName, java.io.Serializable key, byte requesterId)
          Description of the Method
 void removeAll(java.lang.String cacheName)
          Remove all keys from the sepcified remote cache.
 void removeAll(java.lang.String cacheName, byte requesterId)
          Description of the Method
 void removeCacheListener(ICacheListener listener)
          Unsubscribes from all remote caches.
 void removeCacheListener(java.lang.String cacheName, ICacheListener listener)
          Unsubscribes from the specified remote cache.
 void shutdown()
          Description of the Method
 void shutdown(java.lang.String host, int port)
          Description of the Method
 void unreferenced()
          Called by the RMI runtime sometime after the runtime determines that the reference list, the list of clients referencing the remote object, becomes empty.
 void update(ICacheElement item)
          Description of the Method
 void update(ICacheElement item, byte requesterId)
          Description of the Method
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

timing

protected static final boolean timing
Description of the Field

See Also:
Constant Field Values

className

public java.lang.String className
Description of the Field


puts

private int puts

cacheListenersMap

private final java.util.Hashtable cacheListenersMap

clusterListenersMap

private final java.util.Hashtable clusterListenersMap

cacheManager

private CompositeCacheManager cacheManager

idTypeMap

private final java.util.Hashtable idTypeMap

listenerId

private int[] listenerId

rcsa

protected IRemoteCacheServerAttributes rcsa
Description of the Field

Constructor Detail

RemoteCacheServer

protected RemoteCacheServer(IRemoteCacheServerAttributes rcsa)
                     throws java.io.IOException,
                            java.rmi.NotBoundException
Constructor for the RemoteCacheServer object

Parameters:
rcsa -
Throws:
java.io.IOException
java.rmi.NotBoundException
Method Detail

init

protected void init(java.lang.String prop)
             throws java.io.IOException,
                    java.rmi.NotBoundException
RMI Cache Server.

Throws:
java.io.IOException
java.rmi.NotBoundException

createCacheManager

protected CompositeCacheManager createCacheManager(java.lang.String prop)
Subclass can overrdie this method to create the specific cache manager.


getCacheListeners

private CacheListeners getCacheListeners(java.lang.String cacheName)
                                  throws java.io.IOException,
                                         java.rmi.NotBoundException
Returns the cache lsitener for the specified cache. Creates the cache and the cache descriptor if they do not already exist.

Returns:
The cacheListeners value
Throws:
java.io.IOException
java.rmi.NotBoundException

getClusterListeners

private CacheListeners getClusterListeners(java.lang.String cacheName)
                                    throws java.io.IOException,
                                           java.rmi.NotBoundException
Gets the clusterListeners attribute of the RemoteCacheServer object

Returns:
The clusterListeners value
Throws:
java.io.IOException
java.rmi.NotBoundException

put

public void put(ICacheElement item)
         throws java.io.IOException
Puts a cache bean to the remote cache and notifies all listeners which
  1. have a different host than the originating host;
  2. are currently subscribed to the related cache.

Throws:
java.io.IOException

update

public void update(ICacheElement item)
            throws java.io.IOException
Description of the Method

Specified by:
update in interface ICacheService
Throws:
java.io.IOException

update

public void update(ICacheElement item,
                   byte requesterId)
            throws java.io.IOException
Description of the Method

Specified by:
update in interface IRemoteCacheService
Throws:
java.io.IOException

getEventQList

private ICacheEventQueue[] getEventQList(CacheListeners cacheListeners,
                                         byte requesterId)
Gets the eventQList attribute of the RemoteCacheServer object

Returns:
The eventQList value

get

public ICacheElement get(java.lang.String cacheName,
                         java.io.Serializable key)
                  throws java.io.IOException
Returns a cache value from the specified remote cache; or null if the cache or key does not exist.

Specified by:
get in interface ICacheService
Throws:
java.io.IOException

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String cacheName,
                                  java.lang.String group)
Gets the set of keys of objects currently in the group

Specified by:
getGroupKeys in interface IRemoteCacheService

remove

public void remove(java.lang.String cacheName,
                   java.io.Serializable key)
            throws java.io.IOException
Removes the given key from the specified remote cache.

Specified by:
remove in interface ICacheService
Throws:
java.io.IOException

remove

public void remove(java.lang.String cacheName,
                   java.io.Serializable key,
                   byte requesterId)
            throws java.io.IOException
Description of the Method

Specified by:
remove in interface IRemoteCacheService
Throws:
java.io.IOException

removeAll

public void removeAll(java.lang.String cacheName)
               throws java.io.IOException
Remove all keys from the sepcified remote cache.

Specified by:
removeAll in interface ICacheService
Throws:
java.io.IOException

removeAll

public void removeAll(java.lang.String cacheName,
                      byte requesterId)
               throws java.io.IOException
Description of the Method

Specified by:
removeAll in interface IRemoteCacheService
Throws:
java.io.IOException

dispose

public void dispose(java.lang.String cacheName)
             throws java.io.IOException
Frees the specified remote cache.

Specified by:
dispose in interface ICacheService
Throws:
java.io.IOException

dispose

public void dispose(java.lang.String cacheName,
                    byte requesterId)
             throws java.io.IOException
Description of the Method

Throws:
java.io.IOException

release

public void release()
             throws java.io.IOException
Frees all remote caches.

Specified by:
release in interface ICacheService
Throws:
java.io.IOException

getRequester

private java.lang.String getRequester()
Gets the requester attribute of the RemoteCacheServer object

Returns:
The requester value

cleanupEventQMap

private static void cleanupEventQMap(java.util.Map eventQMap)
Description of the Method


addCacheListener

public void addCacheListener(java.lang.String cacheName,
                             ICacheListener listener)
                      throws java.io.IOException
Subscribes to the specified remote cache.

Specified by:
addCacheListener in interface ICacheObserver
Parameters:
cacheName - the specified remote cache.
listener - object to notify for cache changes. must be synchronized since there are remote calls involved.
Throws:
java.io.IOException

addCacheListener

public void addCacheListener(ICacheListener listener)
                      throws java.io.IOException
Subscribes to all remote caches.

Specified by:
addCacheListener in interface ICacheObserver
Parameters:
listener - The feature to be added to the CacheListener attribute
Throws:
java.io.IOException

removeCacheListener

public void removeCacheListener(java.lang.String cacheName,
                                ICacheListener listener)
                         throws java.io.IOException
Unsubscribes from the specified remote cache.

Specified by:
removeCacheListener in interface ICacheObserver
Parameters:
listener - existing subscriber.
Throws:
java.io.IOException

removeCacheListener

public void removeCacheListener(ICacheListener listener)
                         throws java.io.IOException
Unsubscribes from all remote caches.

Specified by:
removeCacheListener in interface ICacheObserver
Parameters:
listener - existing subscriber.
Throws:
java.io.IOException

shutdown

public void shutdown()
              throws java.io.IOException
Description of the Method

Specified by:
shutdown in interface ICacheServiceAdmin
Throws:
java.io.IOException

shutdown

public void shutdown(java.lang.String host,
                     int port)
              throws java.io.IOException
Description of the Method

Specified by:
shutdown in interface ICacheServiceAdmin
Throws:
java.io.IOException

unreferenced

public void unreferenced()
Called by the RMI runtime sometime after the runtime determines that the reference list, the list of clients referencing the remote object, becomes empty.

Specified by:
unreferenced in interface java.rmi.server.Unreferenced

nextListenerId

private byte nextListenerId()
Returns the next generated listener id [0,255].


getStats

public java.lang.String getStats()
                          throws java.io.IOException
Gets the stats attribute of the RemoteCacheServer object

Specified by:
getStats in interface ICacheServiceAdmin
Returns:
The stats value
Throws:
java.io.IOException

p1

private static void p1(java.lang.String s)
Description of the Method