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

java.lang.Object
  extended by com.sun.enterprise.ee.cms.impl.base.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: 1662 $
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)
           
 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)
           
 boolean contains(Object key)
           
 boolean contains(String componentName, Object key)
           
 Map<GMSCacheable,Object> getAllCache()
           
 Map<GMSCacheable,Object> getFromCache(Object key)
           
 Object getFromCache(String componentName, String memberTokenId, Serializable key)
           
 Map<Serializable,Serializable> getFromCacheForPattern(String componentName, String memberToken)
           
 boolean isFirstSyncDone()
           
 void removeAll()
          Empties the DistributedStateCache.
 void removeAllForMember(String memberToken)
           
 void removeFromCache(String componentName, String memberTokenId, Serializable key)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

addToCache

public void addToCache(String componentName,
                       String memberTokenId,
                       Serializable key,
                       Serializable state)
                throws GMSException
Specified by:
addToCache in interface DistributedStateCache
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)
Specified by:
addToLocalCache in interface DistributedStateCache

addToLocalCache

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

addToLocalCache

public void addToLocalCache(GMSCacheable cKey,
                            Object state)

toString

public String toString()
Overrides:
toString in class Object

removeFromCache

public void removeFromCache(String componentName,
                            String memberTokenId,
                            Serializable key)
                     throws GMSException
Specified by:
removeFromCache in interface DistributedStateCache
Throws:
GMSException

getFromCache

public Object getFromCache(String componentName,
                           String memberTokenId,
                           Serializable key)
                    throws GMSException
Specified by:
getFromCache in interface DistributedStateCache
Throws:
GMSException

getAllCache

public Map<GMSCacheable,Object> getAllCache()
Specified by:
getAllCache in interface DistributedStateCache

getFromCacheForPattern

public Map<Serializable,Serializable> getFromCacheForPattern(String componentName,
                                                             String memberToken)
Specified by:
getFromCacheForPattern in interface DistributedStateCache

getFromCache

public Map<GMSCacheable,Object> getFromCache(Object key)
Specified by:
getFromCache in interface DistributedStateCache

contains

public boolean contains(Object key)
Specified by:
contains in interface DistributedStateCache

contains

public boolean contains(String componentName,
                        Object key)
Specified by:
contains in interface DistributedStateCache

isFirstSyncDone

public boolean isFirstSyncDone()
Specified by:
isFirstSyncDone in interface DistributedStateCache

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)
Specified by:
removeAllForMember in interface DistributedStateCache


Copyright © 2012. All Rights Reserved.