org.apache.jcs.auxiliary.javagroups
Class JavaGroupsCache

java.lang.Object
  extended byorg.apache.jcs.auxiliary.javagroups.JavaGroupsCache
All Implemented Interfaces:
AuxiliaryCache, ICache, ICacheType, org.jgroups.MembershipListener, org.jgroups.blocks.RequestHandler, java.io.Serializable

public class JavaGroupsCache
extends java.lang.Object
implements AuxiliaryCache, org.jgroups.blocks.RequestHandler, org.jgroups.MembershipListener

Auxiliary cache using javagroups. Expects to be created with a Channel, the JavaGroupsCacheFactoryis responsible for creating that channel. To do so it uses configuration properties specified by an instance of JavaGroupsCacheAttributes.

At creation time the provided channel is connected to a group having the same name as the cache / region name this auxiliary is associated with. update / remove / removeAll operations are broadcast to all members of the group. A listener thread processes requests from other members of the group, and dispatches to appropriate methods on the associated CompositeCache.

Calls to get are currently ignored.

Messages are sent to peers asynchronously. Synchronous messaging could be added using MessageDispatcher or RpcDispatcher. Combined with a get implementation this could provide much higher cache consistency (but with a substantial speed penalty).

Version:
$Id: JavaGroupsCache.java,v 1.4 2005/06/04 02:01:57 asmuts Exp $
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheType
CACHE_HUB, DISK_CACHE, LATERAL_CACHE, REMOTE_CACHE
 
Constructor Summary
JavaGroupsCache(CompositeCache cache, org.jgroups.Channel channel, boolean getFromPeers)
           
 
Method Summary
 void block()
           
 void dispose()
          Dispose this cache, terminates the listener thread and disconnects the channel from the group.
 ICacheElement get(java.io.Serializable key)
          If 'getFromPeers' is true, this will attempt to get the requested element from ant other members of the group.
 java.lang.String getCacheName()
          Accessor for cacheName property
 int getCacheType()
          Get the cache type (always Lateral).
 java.util.Set getGroupKeys(java.lang.String group)
          Not implemented (I believe since get is not supported, this should also not be).
 int getSize()
          Since this is a lateral, size is not defined.
 IStats getStatistics()
          Returns the historical and statistical data for a region's auxiliary cache.
 java.lang.String getStats()
          getStats
 int getStatus()
          Returns the status of this auxiliary.
 java.lang.Object handle(org.jgroups.Message msg)
          Handles a message from a peer.
 boolean remove(java.io.Serializable key)
          Sends a request to all peers to remove the element having the provided key.
 void removeAll()
          Sends a request to remove ALL elements from the peers
 void send(ICacheElement element, int command)
           
 void suspect(org.jgroups.Address suspectedAddress)
           
 void update(ICacheElement ce)
          Sends the provided element to all peers (connected to the same channel and region name).
 void viewAccepted(org.jgroups.View view)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaGroupsCache

public JavaGroupsCache(CompositeCache cache,
                       org.jgroups.Channel channel,
                       boolean getFromPeers)
                throws java.lang.Exception
Method Detail

send

public void send(ICacheElement element,
                 int command)

update

public void update(ICacheElement ce)
            throws java.io.IOException
Sends the provided element to all peers (connected to the same channel and region name).

Specified by:
update in interface AuxiliaryCache
Parameters:
ce - CacheElement to replicate
Throws:
java.io.IOException - Never thrown by this implementation

get

public ICacheElement get(java.io.Serializable key)
                  throws java.io.IOException
If 'getFromPeers' is true, this will attempt to get the requested element from ant other members of the group.

Specified by:
get in interface AuxiliaryCache
Parameters:
key -
Returns:
Throws:
java.io.IOException - Never thrown by this implementation

remove

public boolean remove(java.io.Serializable key)
               throws java.io.IOException
Sends a request to all peers to remove the element having the provided key.

Specified by:
remove in interface AuxiliaryCache
Parameters:
key - Key of element to be removed
Throws:
java.io.IOException - Never thrown by this implementation

removeAll

public void removeAll()
               throws java.io.IOException
Sends a request to remove ALL elements from the peers

Specified by:
removeAll in interface AuxiliaryCache
Throws:
java.io.IOException - Never thrown by this implementation

dispose

public void dispose()
             throws java.io.IOException
Dispose this cache, terminates the listener thread and disconnects the channel from the group.

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

getSize

public int getSize()
Since this is a lateral, size is not defined.

Specified by:
getSize in interface AuxiliaryCache
Returns:
Always returns 0

getStatus

public int getStatus()
Returns the status of this auxiliary.

Specified by:
getStatus in interface AuxiliaryCache
Returns:
One of the status constants from CacheConstants

getCacheName

public java.lang.String getCacheName()
Accessor for cacheName property

Specified by:
getCacheName in interface AuxiliaryCache
Returns:
Name of cache / region this auxiliary is associated with.

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String group)
Not implemented (I believe since get is not supported, this should also not be).

Specified by:
getGroupKeys in interface AuxiliaryCache
Parameters:
group - Ignored
Returns:
Always reurns null

getCacheType

public int getCacheType()
Get the cache type (always Lateral).

Specified by:
getCacheType in interface ICacheType
Returns:
Always returns ICacheType.LATERAL_CACHE

handle

public java.lang.Object handle(org.jgroups.Message msg)
Handles a message from a peer. The message should contain a Request, and depending on the command this will call localUpdate, localRemove, or localRemoveAll on the associated CompositeCache.

Specified by:
handle in interface org.jgroups.blocks.RequestHandler
Parameters:
msg - The JavaGroups Message
Returns:
Always returns null

viewAccepted

public void viewAccepted(org.jgroups.View view)
Specified by:
viewAccepted in interface org.jgroups.MembershipListener

suspect

public void suspect(org.jgroups.Address suspectedAddress)
Specified by:
suspect in interface org.jgroups.MembershipListener

block

public void block()
Specified by:
block in interface org.jgroups.MembershipListener

getStats

public java.lang.String getStats()
getStats

Specified by:
getStats in interface ICache
Returns:
String

getStatistics

public IStats getStatistics()
Description copied from interface: AuxiliaryCache
Returns the historical and statistical data for a region's auxiliary cache.

Specified by:
getStatistics in interface AuxiliaryCache
Returns:


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