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

This class provides remote cache services. The remote cache server propagates events from local caches to other local caches. It can also store cached data, making it available to new clients. Remote cache servers can be clustered. If the cache used by this remote cache is configured to use a remote cache of type cluster, the two remote caches will communicate with each other. Remote and put requests can be sent from one remote to another. If they are configured to broadcast such event to their client, then remove an puts can be sent to all locals in the cluster. However, get requests are not made between clustered servers. You can setup several clients to use one remote server and several to use another. The get locad will be distributed between the two servers. Since caches are usually high get and low put, this should allow you to scale.

See Also:
Serialized Form

Field Summary
 java.lang.String className
          Description of the Field
protected  IRemoteCacheServerAttributes rcsa
          Description of the Field
protected static boolean timing
          Description of the Field
 
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.
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, long requesterId)
          Frees the specified remote cache.
 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.
 java.util.Set getGroupKeys(java.lang.String cacheName, java.lang.String group)
          Gets the set of keys of objects currently in the group.
 java.lang.String getStats()
          Gets the stats attribute of the RemoteCacheServer object
protected  void init(java.lang.String prop)
          Initialize the RMI Cache Server from a proeprties file.
 void put(ICacheElement item)
          Puts a cache bean to the remote cache and notifies all listeners which
have a different listener id 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, long requesterId)
          Remove the key from the cache region and don't tell the source listener about it.
 void removeAll(java.lang.String cacheName)
          Remove all keys from the sepcified remote cache.
 void removeAll(java.lang.String cacheName, long requesterId)
          Remove all keys from the sepcified remote cache.
 void removeCacheListener(ICacheListener listener)
          Unsubscribes from all remote caches.
 void removeCacheListener(java.lang.String cacheName, ICacheListener listener)
          Unsubscribes from the specified cache.
 void removeCacheListener(java.lang.String cacheName, long listenerId)
          Unsibscribe this region.
 void shutdown()
          Shuts down the remote server.
 void shutdown(java.lang.String host, int port)
          Shuts down a server at a particular host and port.
 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)
          Puts a cache item to the cache.
 void update(ICacheElement item, long requesterId)
          An update can come from either a local cache's remote auxiliary, or it can come from a remote server.
 
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

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


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
Initialize the RMI Cache Server from a proeprties file.

Parameters:
prop -
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.

Parameters:
prop - The anem of the configuration file.
Returns:
The cache hub configured with this configuration file.

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 listener id than the originating host;
  2. are currently subscribed to the related cache.

Parameters:
item -
Throws:
java.io.IOException

update

public void update(ICacheElement item)
            throws java.io.IOException
Description copied from interface: ICacheService
Puts a cache item to the cache.

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

update

public void update(ICacheElement item,
                   long requesterId)
            throws java.io.IOException
An update can come from either a local cache's remote auxiliary, or it can come from a remote server. A remote server is considered a a source of type cluster. If the update came from a cluster, then we should tell the cache manager that this was a remote put. This way, any lateral and remote auxiliaries configured for the region will not be updated. This is basically how a remote listener works when plugged into a local cache. If the cluster is configured to keep local cluster consistency, then all listeners will be updated. This allows cluster server A to update cluster server B and then B to update its clients if it is told to keep local cluster consistency. Otherwise, server A will update server B and B will not tell its clients. If you cluster using lateral caches for instance, this is how it will work. Updates to a cluster node, will never get to the leavess. The remote cluster, with local cluster consistency, allows you to update leaves. This basically allows you to have a failover remote server. Since currently a cluster will not try to get from other cluster servers, you can scale a bit with a cluster configuration. Puts and removes will be broadcasted to all clients, but the get load on a remote server can be reduced.

Specified by:
update in interface IRemoteCacheService
Parameters:
item -
requesterId -
Throws:
java.io.IOException

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
Parameters:
cacheName -
key -
Returns:
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
Parameters:
cacheName -
group -
Returns:
A Set of group keys

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. Defaults the listener id to 0.

Specified by:
remove in interface ICacheService
Parameters:
cacheName -
key -
Throws:
java.io.IOException

remove

public void remove(java.lang.String cacheName,
                   java.io.Serializable key,
                   long requesterId)
            throws java.io.IOException
Remove the key from the cache region and don't tell the source listener about it.

Specified by:
remove in interface IRemoteCacheService
Parameters:
cacheName -
key -
requesterId -
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
Parameters:
cacheName -
Throws:
java.io.IOException

removeAll

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

Specified by:
removeAll in interface IRemoteCacheService
Parameters:
cacheName -
requesterId -
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
Parameters:
cacheName -
Throws:
java.io.IOException

dispose

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

Parameters:
cacheName -
requesterId -
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

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
Description copied from interface: ICacheObserver
Unsubscribes from the specified cache.

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

removeCacheListener

public void removeCacheListener(java.lang.String cacheName,
                                long listenerId)
                         throws java.io.IOException
Unsibscribe this region.

Parameters:
cacheName -
listenerId -
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 -
Throws:
java.io.IOException

shutdown

public void shutdown()
              throws java.io.IOException
Shuts down the remote server.

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

shutdown

public void shutdown(java.lang.String host,
                     int port)
              throws java.io.IOException
Shuts down a server at a particular host and port.

Specified by:
shutdown in interface ICacheServiceAdmin
Parameters:
host -
port -
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

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


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