com.sun.enterprise.ee.cms.impl.jxta
Class DistributedStateCacheImpl

java.lang.Object
  extended by com.sun.enterprise.ee.cms.impl.jxta.DistributedStateCacheImpl
All Implemented Interfaces:
DistributedStateCache

public class DistributedStateCacheImpl
extends Object
implements DistributedStateCache

Messaging based implementation of a shared distributed state cache(DSC). Every write entry made such as adding a new entry or removing an existing entry is disseminated to all group members through a message. Read-only operation i.e getFromCache() is a local call. During startup of a member, a singleton instance of this class is created. This instance is available to GMS client components in this member through GroupHandle.getDistributedStateCache() so that the client components can read or write to this cache.

When an entry is added or removed, this implementation uses underlying GroupCommunicationProvider(GCP) to sends a message to the all members of the group. The recipients in turn call corresponding method for adding or removing the entry to/from their copy of the this DistributedStateCache implementation.

When new member joins the group, the join notification is received on every member. When this happens, and if this member is a leader of the group, then it uses the GCP's messaging api to sends a message to the new member to pass on the current state of this DSC. The remote member updates its DSC with this current state while returning its own state to this member through another message. This member updates its own DSC with this new entry resulting in all members getting this updated state. This brings the group-wide DSC into a synchronized state.

This initial sync-up is a heavy weight operation particularly during startup of the whole group concurrently as new members are joining the group rapidly. To prevent data loss during such times, each sync activity will require a blocking call to ensure that rapid group view changes during group startup will not result in data loss.

Version:
$Revision: 1.23 $
Author:
Shreedhar Ganapathy Date: June 20, 2006

Method Summary
 void addToCache(String componentName, String memberTokenId, Serializable key, byte[] state)
           
 void addToCache(String componentName, String memberTokenId, Serializable key, Serializable state)
          Caches a serializable object representing state to be cached.
 void addToLocalCache(GMSCacheable cKey, Object state)
           
 void addToLocalCache(String componentName, String memberTokenId, Serializable key, byte[] state)
           
 void addToLocalCache(String componentName, String memberTokenId, Serializable key, Serializable state)
          Locally caches a serializable object representing state to be cached.
 boolean contains(Object key)
          returns true if the DSC contains an entry wherein the component key portion of the composite key in the DSC is the same as the key specified in the argument
 boolean contains(String componentName, Object key)
          returns true if the DSC contains an entry wherein the componentName and the componet key portion of the composite key in the DSC is the same as the parameters specified in the argument
 Map<GMSCacheable,Object> getAllCache()
          returns the current cache state to caller.
 Map<GMSCacheable,Object> getFromCache(Object key)
          returns a Map containing entries that are in the DSC where either the componentName or the memberToken or the key is the same as the key specified in the argument.
 Object getFromCache(String componentName, String memberTokenId, Serializable key)
          retrieves the cache for the given composite key of component name, member token id and the key.
 Map<Serializable,Serializable> getFromCacheForPattern(String componentName, String memberToken)
          returns a Map containing key-value pairs matching entries that have keys with the given componentName and memberToken
 boolean isFirstSyncDone()
          returns true if this cache has been sync'd with any other member For implementations that do not intend to have a synchronized cache on all members, this method can be a no-op
 void removeAll()
          Empties the DistributedStateCache.
 void removeAllForMember(String memberToken)
          Empties the DistributedStateCache entries pertaining to a particular member.
 void removeFromCache(String componentName, String memberTokenId, Serializable key)
          removes an entry from the cache for the given composite key of the component name, member token id and the specific key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addToCache

public void addToCache(String componentName,
                       String memberTokenId,
                       Serializable key,
                       Serializable state)
                throws GMSException
Description copied from interface: DistributedStateCache
Caches a serializable object representing state to be cached. The key to this cache for the implementation is the composite key comprising the component name, the memberTokenId and the component-provided key itself.

Specified by:
addToCache in interface DistributedStateCache
Parameters:
componentName - - name of the GMS client component that is storing this cache
memberTokenId - - member token Id of this member
key - - a serializable key that differentiates this cache from other caches of the same component and member.
state - - a serializable object representing the cachable state
Throws:
GMSException

addToCache

public void addToCache(String componentName,
                       String memberTokenId,
                       Serializable key,
                       byte[] state)
                throws GMSException
Throws:
GMSException

addToLocalCache

public void addToLocalCache(String componentName,
                            String memberTokenId,
                            Serializable key,
                            Serializable state)
Description copied from interface: DistributedStateCache
Locally caches a serializable object representing state to be cached. The key to this cache for the implementation is the composite key comprising the component name, the memberTokenId and the component-provided key itself. NOTE: Calling this method does not result in information being shared with remote members. This is for local storage only.

Specified by:
addToLocalCache in interface DistributedStateCache
Parameters:
componentName - Name of GMS Client component
memberTokenId - Member's identity
key - - an Object
state - - an Object

addToLocalCache

public void addToLocalCache(String componentName,
                            String memberTokenId,
                            Serializable key,
                            byte[] state)

addToLocalCache

public void addToLocalCache(GMSCacheable cKey,
                            Object state)

removeFromCache

public void removeFromCache(String componentName,
                            String memberTokenId,
                            Serializable key)
                     throws GMSException
Description copied from interface: DistributedStateCache
removes an entry from the cache for the given composite key of the component name, member token id and the specific key.

Specified by:
removeFromCache in interface DistributedStateCache
Parameters:
componentName - Name of GMS Client component
memberTokenId - Member's identity
key - The component provided key
Throws:
GMSException

getFromCache

public Object getFromCache(String componentName,
                           String memberTokenId,
                           Serializable key)
                    throws GMSException
Description copied from interface: DistributedStateCache
retrieves the cache for the given composite key of component name, member token id and the key. Returns a cached Serializable object.

Specified by:
getFromCache in interface DistributedStateCache
Parameters:
componentName - Name of GMS Client component
memberTokenId - Member's identity
key - - a serializable key that differentiates this cache entry from other cache entries.
Returns:
Object
Throws:
GMSException

getAllCache

public Map<GMSCacheable,Object> getAllCache()
Description copied from interface: DistributedStateCache
returns the current cache state to caller.

Specified by:
getAllCache in interface DistributedStateCache
Returns:
Map - containing the cache of this DSC instance

getFromCacheForPattern

public Map<Serializable,Serializable> getFromCacheForPattern(String componentName,
                                                             String memberToken)
Description copied from interface: DistributedStateCache
returns a Map containing key-value pairs matching entries that have keys with the given componentName and memberToken

Specified by:
getFromCacheForPattern in interface DistributedStateCache
Parameters:
componentName - Name of GMS Client component
memberToken - Member's identity
Returns:
Map - containing key value pairs for all entries that have the given component name and memberToken

getFromCache

public Map<GMSCacheable,Object> getFromCache(Object key)
Description copied from interface: DistributedStateCache
returns a Map containing entries that are in the DSC where either the componentName or the memberToken or the key is the same as the key specified in the argument.

Specified by:
getFromCache in interface DistributedStateCache
Parameters:
key - The key here is one of MemberToken, ComponentName, or the component-provided key itself
Returns:
Map

contains

public boolean contains(Object key)
Description copied from interface: DistributedStateCache
returns true if the DSC contains an entry wherein the component key portion of the composite key in the DSC is the same as the key specified in the argument

Specified by:
contains in interface DistributedStateCache
Parameters:
key - component-provided key
Returns:
boolean true if the component-provided key exists in cache

contains

public boolean contains(String componentName,
                        Object key)
Description copied from interface: DistributedStateCache
returns true if the DSC contains an entry wherein the componentName and the componet key portion of the composite key in the DSC is the same as the parameters specified in the argument

Specified by:
contains in interface DistributedStateCache
Parameters:
componentName - Name of component
key - component-provided key
Returns:
boolean true if the key for the specified component exists

isFirstSyncDone

public boolean isFirstSyncDone()
Description copied from interface: DistributedStateCache
returns true if this cache has been sync'd with any other member For implementations that do not intend to have a synchronized cache on all members, this method can be a no-op

Specified by:
isFirstSyncDone in interface DistributedStateCache
Returns:
boolean

removeAll

public void removeAll()
Empties the DistributedStateCache. This is typically called in a group shutdown context so that the group's stale data is not retained for any later lives of the group.

Specified by:
removeAll in interface DistributedStateCache

removeAllForMember

public void removeAllForMember(String memberToken)
Description copied from interface: DistributedStateCache
Empties the DistributedStateCache entries pertaining to a particular member. If this member's id appears in any part of the key or value of the cache, then that entry is removed. Typically, this is called when a particular member is being administratively shutdown and remaining members internally call this api when notified of this impending shutdown.

Specified by:
removeAllForMember in interface DistributedStateCache
Parameters:
memberToken - member's identity


Copyright © 2003 Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.