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:
ClusterStoreManager, FileStore

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

Base class for distributed stores.


Field Summary
protected  LruCache<java.lang.String,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<java.lang.String,Store> _storeMap
           
protected static java.util.logging.Logger log
           
 
Constructor Summary
protected StoreManager()
           
 
Method Summary
 void access(Store store, java.lang.String id)
          Updates the object's access time.
 void access(java.lang.String uniqueId)
          Updates the object's access time.
abstract  void accessImpl(java.lang.String uniqueId)
          Updates the object's access time in the persistent store.
 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.
 Store createStore(java.lang.String storeId, ObjectManager objectManager)
          Creates a Store.
 void destroy()
          Called at end of life.
 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 store 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 load.
 long getMaxIdleTime()
          Returns the length of time an idle object can remain in the store before being cleaned.
 long getObjectCount()
          Returns the objects in the store
protected  ServerConnector 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  ServerConnector[] getServerList()
          Returns the list of cluster servers.
 Store getStore(java.lang.String storeId)
          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.
 boolean isAlwaysLoad()
          Set true if the store should always try to load the object.
 boolean isAlwaysSave()
          Set true if the store should always try to store 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 object access time.
 void remove(ClusterObject obj)
          When the object is no longer valid, remove it from the backing store.
 void remove(Store store, java.lang.String objectId)
          When the object is no longer valid, remove it from the backing store.
 Store removeStore(java.lang.String storeId)
          Removes a Store.
 void setAlwaysLoad(boolean alwaysLoad)
          Set true if the store should always try to load the object.
 void setAlwaysSave(boolean alwaysSave)
          Set true if the store should always try to store the object.
 void setCluster(Cluster cluster)
          Sets the cluster.
 void setExpireInterval(java.lang.String 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 store before being cleaned.
 boolean start()
          Called to start the store.
protected abstract  void store(ClusterObject clusterObject, TempStream tempStream, long crc)
          Save the object to the store.
 void store(Store store, java.lang.String id, java.lang.Object obj)
          Saves the object to the cluster.
 void update(java.lang.String storeId, java.lang.String objectId)
          When the object is no longer valid, remove it from the backing store.
 void updateIdleCheckInterval(long idleCheckInterval)
          Sets the idle check interval for the alarm.
 void updateOwner(java.lang.String objectId, java.lang.String uniqueId)
          Updates the owner object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log

_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<java.lang.String,Store> _storeMap

_clusterObjects

protected LruCache<java.lang.String,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 store should always try to load the object.


isAlwaysLoad

public boolean isAlwaysLoad()
Set true if the store should always try to load the object.


setAlwaysSave

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


isAlwaysSave

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


getMaxIdleTime

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


setMaxIdleTime

public void setMaxIdleTime(Period maxIdleTime)
Sets the length of time an idle object can remain in the store 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 store before being cleaned.


getObjectCount

public long getObjectCount()
Returns the objects in the store


getLoadCount

public long getLoadCount()
Returns the total objects loaded.


getLoadFailCount

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


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(java.lang.String storeId)
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(java.lang.String storeId)
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()
             throws java.lang.Exception
Called after any factory settings.

Throws:
java.lang.Exception

start

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

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 store 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 object access time.

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

access

public void access(java.lang.String uniqueId)
            throws java.lang.Exception
Updates the object's access time.

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

access

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

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

accessImpl

public abstract void accessImpl(java.lang.String uniqueId)
                         throws java.lang.Exception
Updates the object's access time in the persistent store.

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

setExpireInterval

public void setExpireInterval(java.lang.String 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

update

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

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

updateOwner

public void updateOwner(java.lang.String objectId,
                        java.lang.String uniqueId)
                 throws java.lang.Exception
Updates the owner object.

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

store

public void store(Store store,
                  java.lang.String id,
                  java.lang.Object obj)
           throws java.io.IOException
Saves the object to the cluster.

Parameters:
storeId - the identifier of the storage group
obj - the object to store.
Throws:
java.io.IOException

store

protected abstract void store(ClusterObject clusterObject,
                              TempStream tempStream,
                              long crc)
                       throws java.lang.Exception
Save the object to the store.

Parameters:
storeId - the identifier of the storage group
obj - the object to store.
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, remove it from the backing store.

Parameters:
obj - the object to remove
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, remove it from the backing store.

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

getSelfIndex

protected int getSelfIndex()
Returns the self servers.


getServerList

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


getOwningServer

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


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.