com.caucho.server.cluster
Class StoreManager

java.lang.Object
  extended by com.caucho.server.cluster.StoreManager
All Implemented Interfaces:
ClassLoaderListener, EnvironmentListener, AlarmListener, java.util.EventListener
Direct Known Subclasses:
AbstractClusterStoreManager, FileStoreManager

public abstract class StoreManager
extends java.lang.Object
implements AlarmListener, EnvironmentListener, ClassLoaderListener

Base class for distributed stores.


Field Summary
protected  LruCache<HashKey,ClusterObject> _clusterObjects
           
protected  long _idleCheckInterval
           
protected  boolean _isAlwaysLoad
           
protected  boolean _isAlwaysSave
           
protected  long _loadCount
           
protected  long _loadFailCount
           
protected  long _maxIdleTime
           
protected  long _saveCount
           
protected  long _saveFailCount
           
protected  int _selfIndex
           
protected  java.util.HashMap<HashKey,Store> _storeMap
           
 
Constructor Summary
protected StoreManager()
           
 
Method Summary
 void access(HashKey objectId)
          Updates the object's objectAccess time.
 void access(Store store, java.lang.String id)
          Updates the object's objectAccess time.
 void accessImpl(ClusterObject obj)
          Updates the object's objectAccess time in the persistent objectStore.
abstract  void accessImpl(HashKey objectId)
          Updates the object's objectAccess time in the persistent objectStore.
 void classLoaderDestroy(DynamicClassLoader loader)
          Handles the case where the environment loader is dropped.
 void classLoaderInit(DynamicClassLoader loader)
          Handles the case where the environment is activated.
 void clearOldObjects()
          Cleans old objects.
protected  ClusterObject create(Store store, HashKey key, int primary, int secondary, int tertiary)
          Creates the cluster object.
 Store createStore(java.lang.String storeId, ObjectManager objectManager)
          Creates a Store.
 void destroy()
          Called at end of life.
 void environmentBind(EnvironmentClassLoader loader)
          Handles the case where the environment is activated.
 void environmentConfigure(EnvironmentClassLoader loader)
          Handles the case where the environment is in the configuration
 void environmentStart(EnvironmentClassLoader loader)
          Handles the case where the environment is activated.
 void environmentStop(EnvironmentClassLoader loader)
          Handles the case where the environment loader is stops
 long getAccessWindowTime()
          Returns the length of time an idle object can remain in the objectStore before being cleaned.
 PersistentStoreMXBean getAdmin()
          Returns the admin.
 Cluster getCluster()
          Gets the cluster.
 long getIdleCheckTime()
          Sets the idle check interval for the alarm.
 long getLoadCount()
          Returns the total objects loaded.
 long getLoadFailCount()
          Returns the objects which failed to loadImpl.
 long getMaxIdleTime()
          Returns the length of time an idle object can remain in the objectStore before being cleaned.
 long getObjectCount()
          Returns the objects in the objectStore
protected  ClusterServer getOwningServer(java.lang.String objectId)
          Returns the cluster server which owns the object
 int getPrimaryIndex(java.lang.String id, int offset)
          Returns the owning index.
 long getSaveCount()
          Returns the total objects saved.
 long getSaveFailCount()
          Returns the objects which failed to save.
 int getSecondaryIndex(java.lang.String id, int offset)
          Returns the backup index.
protected  int getSelfIndex()
          Returns the self servers.
protected  ClusterServer[] getServerList()
          Returns the list of cluster servers.
 Store getStore(HashKey storeKey)
          Creates a ClusterObjectManager.
 int getTertiaryIndex(java.lang.String id, int offset)
          Returns the backup index.
 void handleAlarm(Alarm alarm)
          Handles a callback from an alarm, scheduling the timeout.
 boolean init()
          Called after any factory settings.
 void invalidate(HashKey objectId)
          Notify the object that the data has changed.
 boolean isAlwaysLoad()
          Set true if the objectStore should always try to loadImpl the object.
 boolean isAlwaysSave()
          Set true if the objectStore should always try to objectStore the object.
protected  boolean isPrimary(java.lang.String id)
          Returns true if this server is a primary for the given object id.
protected abstract  boolean load(ClusterObject clusterObject, java.lang.Object obj)
          Loads an object from the backing objectStore.
 void remove(ClusterObject obj)
          When the object is no longer valid, objectRemove it from the backing objectStore.
 void remove(Store store, java.lang.String objectId)
          When the object is no longer valid, objectRemove it from the backing objectStore.
 Store removeStore(HashKey storeKey)
          Removes a Store.
 void setAlwaysLoad(boolean alwaysLoad)
          Set true if the objectStore should always try to loadImpl the object.
 void setAlwaysSave(boolean alwaysSave)
          Set true if the objectStore should always try to objectStore the object.
 void setCluster(Cluster cluster)
          Sets the cluster.
 void setExpireInterval(HashKey uniqueId, long expires)
          Sets the timef for the expires interval.
 void setMaxIdleTime(Period maxIdleTime)
          Sets the length of time an idle object can remain in the objectStore before being cleaned.
 boolean start()
          Called to start the objectStore.
 boolean startUpdate()
          Called to start any invalidate processing
protected abstract  void store(ClusterObject clusterObject, TempOutputStream tempStream, byte[] dataHash, byte[] oldDataHash)
          Save the object to the objectStore.
 java.lang.String toString()
           
 void updateIdleCheckInterval(long idleCheckInterval)
          Sets the idle check interval for the alarm.
 void updateOwner(ClusterObject objectId)
          Updates the owner object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_selfIndex

protected int _selfIndex

_maxIdleTime

protected long _maxIdleTime

_idleCheckInterval

protected long _idleCheckInterval

_isAlwaysLoad

protected boolean _isAlwaysLoad

_isAlwaysSave

protected boolean _isAlwaysSave

_storeMap

protected java.util.HashMap<HashKey,Store> _storeMap

_clusterObjects

protected LruCache<HashKey,ClusterObject> _clusterObjects

_loadCount

protected volatile long _loadCount

_loadFailCount

protected volatile long _loadFailCount

_saveCount

protected volatile long _saveCount

_saveFailCount

protected volatile long _saveFailCount
Constructor Detail

StoreManager

protected StoreManager()
Method Detail

setCluster

public void setCluster(Cluster cluster)
Sets the cluster.


getCluster

public Cluster getCluster()
Gets the cluster.


getAdmin

public PersistentStoreMXBean getAdmin()
Returns the admin.


setAlwaysLoad

public void setAlwaysLoad(boolean alwaysLoad)
Set true if the objectStore should always try to loadImpl the object.


isAlwaysLoad

public boolean isAlwaysLoad()
Set true if the objectStore should always try to loadImpl the object.


setAlwaysSave

public void setAlwaysSave(boolean alwaysSave)
Set true if the objectStore should always try to objectStore the object.


isAlwaysSave

public boolean isAlwaysSave()
Set true if the objectStore should always try to objectStore the object.


getMaxIdleTime

public long getMaxIdleTime()
Returns the length of time an idle object can remain in the objectStore before being cleaned.


setMaxIdleTime

public void setMaxIdleTime(Period maxIdleTime)
Sets the length of time an idle object can remain in the objectStore before being cleaned.


updateIdleCheckInterval

public void updateIdleCheckInterval(long idleCheckInterval)
Sets the idle check interval for the alarm.


getIdleCheckTime

public long getIdleCheckTime()
Sets the idle check interval for the alarm.


getAccessWindowTime

public long getAccessWindowTime()
Returns the length of time an idle object can remain in the objectStore before being cleaned.


getObjectCount

public long getObjectCount()
Returns the objects in the objectStore


getLoadCount

public long getLoadCount()
Returns the total objects loaded.


getLoadFailCount

public long getLoadFailCount()
Returns the objects which failed to loadImpl.


getSaveCount

public long getSaveCount()
Returns the total objects saved.


getSaveFailCount

public long getSaveFailCount()
Returns the objects which failed to save.


createStore

public Store createStore(java.lang.String storeId,
                         ObjectManager objectManager)
Creates a Store. The Store manages persistent objects for a particular domain, like the sesions for the /foo URL.

Parameters:
storeId - the persistent domain.

removeStore

public Store removeStore(HashKey storeKey)
Removes a Store. The Store manages persistent objects for a particular domain, like the sesions for the /foo URL.

Parameters:
storeId - the persistent domain.

getStore

public Store getStore(HashKey storeKey)
Creates a ClusterObjectManager. The ClusterObjectManager manages persistent objects for a particular domain, like the sesions for the /foo URL.

Parameters:
storeId - the persistent domain.

init

public boolean init()
Called after any factory settings.


start

public boolean start()
              throws java.lang.Exception
Called to start the objectStore.

Throws:
java.lang.Exception

startUpdate

public boolean startUpdate()
                    throws java.lang.Exception
Called to start any invalidate processing

Throws:
java.lang.Exception

clearOldObjects

public void clearOldObjects()
                     throws java.lang.Exception
Cleans old objects. Living objects corresponding to the old objects are not cleared, since their timeout should be less than the objectStore timeout.

Throws:
java.lang.Exception

isPrimary

protected boolean isPrimary(java.lang.String id)
Returns true if this server is a primary for the given object id.


getPrimaryIndex

public int getPrimaryIndex(java.lang.String id,
                           int offset)
Returns the owning index.


getSecondaryIndex

public int getSecondaryIndex(java.lang.String id,
                             int offset)
Returns the backup index.


getTertiaryIndex

public int getTertiaryIndex(java.lang.String id,
                            int offset)
Returns the backup index.


load

protected abstract boolean load(ClusterObject clusterObject,
                                java.lang.Object obj)
                         throws java.lang.Exception
Loads an object from the backing objectStore.

Parameters:
obj - the object to updateImpl.
Throws:
java.lang.Exception

access

public void access(HashKey objectId)
            throws java.lang.Exception
Updates the object's objectAccess time.

Parameters:
storeId - the identifier of the storage group
obj - the object to updateImpl.
Throws:
java.lang.Exception

access

public void access(Store store,
                   java.lang.String id)
            throws java.lang.Exception
Updates the object's objectAccess time.

Parameters:
storeId - the identifier of the storage group
obj - the object to updateImpl.
Throws:
java.lang.Exception

accessImpl

public abstract void accessImpl(HashKey objectId)
                         throws java.lang.Exception
Updates the object's objectAccess time in the persistent objectStore.

Parameters:
uniqueId - the identifier of the object.
Throws:
java.lang.Exception

accessImpl

public void accessImpl(ClusterObject obj)
                throws java.lang.Exception
Updates the object's objectAccess time in the persistent objectStore.

Parameters:
uniqueId - the identifier of the object.
Throws:
java.lang.Exception

setExpireInterval

public void setExpireInterval(HashKey uniqueId,
                              long expires)
                       throws java.lang.Exception
Sets the timef for the expires interval.

Parameters:
uniqueId - the identifier of the object.
long - the time in ms for the expire
Throws:
java.lang.Exception

invalidate

public void invalidate(HashKey objectId)
                throws java.lang.Exception
Notify the object that the data has changed.

Parameters:
objectId - the identifier of the object to notify
Throws:
java.lang.Exception

updateOwner

public void updateOwner(ClusterObject objectId)
                 throws java.lang.Exception
Updates the owner object.

Parameters:
uniqueId - the identifier of the storage group
Throws:
java.lang.Exception

create

protected ClusterObject create(Store store,
                               HashKey key,
                               int primary,
                               int secondary,
                               int tertiary)
Creates the cluster object.


store

protected abstract void store(ClusterObject clusterObject,
                              TempOutputStream tempStream,
                              byte[] dataHash,
                              byte[] oldDataHash)
                       throws java.lang.Exception
Save the object to the objectStore.

Parameters:
clusterObject - the distributed handle
tempStream - the byte stream to the saved data
dataHash - the sha-1 hash of the data
oldDataHash - the previous hash value for the data
Throws:
java.lang.Exception

handleAlarm

public void handleAlarm(Alarm alarm)
Handles a callback from an alarm, scheduling the timeout.

Specified by:
handleAlarm in interface AlarmListener

remove

public void remove(ClusterObject obj)
            throws java.lang.Exception
When the object is no longer valid, objectRemove it from the backing objectStore.

Parameters:
obj - the object to objectRemove
Throws:
java.lang.Exception

remove

public void remove(Store store,
                   java.lang.String objectId)
            throws java.lang.Exception
When the object is no longer valid, objectRemove it from the backing objectStore.

Parameters:
objectStore - the identifier of the storeage group
objectId - the identifier of the object to objectRemove
Throws:
java.lang.Exception

getSelfIndex

protected int getSelfIndex()
Returns the self servers.


getServerList

protected ClusterServer[] getServerList()
Returns the list of cluster servers.


getOwningServer

protected ClusterServer getOwningServer(java.lang.String objectId)
Returns the cluster server which owns the object


environmentConfigure

public void environmentConfigure(EnvironmentClassLoader loader)
Handles the case where the environment is in the configuration

Specified by:
environmentConfigure in interface EnvironmentListener

environmentBind

public void environmentBind(EnvironmentClassLoader loader)
Handles the case where the environment is activated.

Specified by:
environmentBind in interface EnvironmentListener

environmentStart

public void environmentStart(EnvironmentClassLoader loader)
Handles the case where the environment is activated.

Specified by:
environmentStart in interface EnvironmentListener

environmentStop

public void environmentStop(EnvironmentClassLoader loader)
Handles the case where the environment loader is stops

Specified by:
environmentStop in interface EnvironmentListener

classLoaderInit

public void classLoaderInit(DynamicClassLoader loader)
Handles the case where the environment is activated.

Specified by:
classLoaderInit in interface ClassLoaderListener

classLoaderDestroy

public void classLoaderDestroy(DynamicClassLoader loader)
Handles the case where the environment loader is dropped.

Specified by:
classLoaderDestroy in interface ClassLoaderListener

destroy

public void destroy()
Called at end of life.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object