org.jboss.ha.hasessionstate.server
Class HASessionStateImpl

java.lang.Object
  extended byorg.jboss.ha.hasessionstate.server.HASessionStateImpl
All Implemented Interfaces:
HAPartition.HAPartitionStateTransfer (src) , HASessionState (src)

public class HASessionStateImpl
extends java.lang.Object
implements HASessionState (src) , HAPartition.HAPartitionStateTransfer (src)

Default implementation of HASessionState

See Also:
HASessionState (src)

Nested Class Summary
 
Nested classes inherited from class org.jboss.ha.hasessionstate.interfaces.HASessionState (src)
HASessionState.HASessionStateListener (src)
 
Field Summary
protected  java.lang.String _sessionStateName
           
protected  java.util.Hashtable appSessions
           
protected  long beanCleaningDelay
           
protected  java.lang.String DEFAULT_PARTITION_JNDI_NAME
           
protected static java.lang.String HA_SESSION_STATE_STATE_TRANSFER
           
protected  java.lang.String haPartitionJndiName
           
protected  java.lang.String haPartitionName
           
protected  HAPartition (src) hapGeneral
           
protected  java.lang.String JNDI_FOLDER_NAME_FOR_HAPARTITION
           
protected  java.lang.String JNDI_FOLDER_NAME_FOR_HASESSIONSTATE
           
protected  java.util.Hashtable listeners
           
protected  java.lang.Object lockAppSession
           
protected  java.util.HashMap locks
           
protected  Logger (src) log
           
protected  long MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE
           
protected  java.lang.String myNodeName
           
protected  java.lang.String sessionStateIdentifier
           
 
Constructor Summary
HASessionStateImpl()
           
HASessionStateImpl(java.lang.String sessionStateName, java.lang.String mainHAPartitionName, long beanCleaningDelay)
           
 
Method Summary
 PackagedSessionImpl (src) _createSession(java.lang.String appName, java.lang.Object keyId)
           
 void _removeSession(java.lang.String appName, java.lang.Object keyId)
           
 java.lang.Boolean _setOwnership(java.lang.String appName, java.lang.Object keyId, java.lang.String newOwner, java.lang.Long remoteVersion)
           
 void _setState(java.lang.String appName, PackagedSession (src)  session)
           
protected  void bind(java.lang.String jndiName, java.lang.Object who, java.lang.Class classType, javax.naming.Context ctx)
           
 void createSession(java.lang.String appName, java.lang.Object keyId)
          Share a new session state in the sub-partition of this cluster
protected  byte[] deflate(java.lang.Object object)
           
 HAPartition (src) getCurrentHAPartition()
           
 java.io.Serializable getCurrentState()
          Called when a new node need to be initialized.
protected  java.util.Hashtable getHashtableForApp(java.lang.String appName)
           
protected  Mutex getLock(java.lang.String appName, java.lang.Object key)
           
 java.lang.String getNodeName()
          Return the name of this node as used in the computations
 PackagedSession (src) getState(java.lang.String appName, java.lang.Object keyId)
          Get a particular state
 PackagedSession (src) getStateWithOwnership(java.lang.String appName, java.lang.Object keyId)
          Get a state and, if it is not already the case, takes its ownership (a state is always owned by a node)
protected  java.lang.Object inflate(byte[] compressedContent)
           
 void init()
           
 PackagedSession (src) localTakeOwnership(java.lang.String appName, java.lang.Object keyId)
           
protected  boolean lockExists(java.lang.String appName, java.lang.Object key)
           
 void ownedObjectExternallyModified(java.lang.String appName, java.lang.Object key, PackagedSession (src)  oldSession, PackagedSession (src)  newSession)
           
 void purgeState()
           
protected  void removeLock(java.lang.String appName, java.lang.Object key)
           
 void removeSession(java.lang.String appName, java.lang.Object keyId)
          Remove a session from the sub-partition
 void setCurrentState(java.io.Serializable newState)
          This callback method is called when a new service starts on a new node: the state that it should hold is transfered to it through this callback
 void setState(java.lang.String appName, java.lang.Object keyId, byte[] state)
          Modifies a state already shared
 void start()
           
 void stop()
           
 void subscribe(java.lang.String appName, HASessionState.HASessionStateListener (src)  listener)
          Subscribe to receive notifications when objects gets modified on another node.
 void takeOwnership(java.lang.String appName, java.lang.Object keyId)
          Take ownership of a state.
 void unsubscribe(java.lang.String appName, HASessionState.HASessionStateListener (src)  listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sessionStateName

protected java.lang.String _sessionStateName

log

protected Logger (src)  log

hapGeneral

protected HAPartition (src)  hapGeneral

sessionStateIdentifier

protected java.lang.String sessionStateIdentifier

myNodeName

protected java.lang.String myNodeName

beanCleaningDelay

protected long beanCleaningDelay

haPartitionName

protected java.lang.String haPartitionName

haPartitionJndiName

protected java.lang.String haPartitionJndiName

DEFAULT_PARTITION_JNDI_NAME

protected final java.lang.String DEFAULT_PARTITION_JNDI_NAME

JNDI_FOLDER_NAME_FOR_HASESSIONSTATE

protected final java.lang.String JNDI_FOLDER_NAME_FOR_HASESSIONSTATE
See Also:
Constant Field Values (src)

JNDI_FOLDER_NAME_FOR_HAPARTITION

protected final java.lang.String JNDI_FOLDER_NAME_FOR_HAPARTITION
See Also:
Constant Field Values (src)

MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE

protected final long MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE
See Also:
Constant Field Values (src)

HA_SESSION_STATE_STATE_TRANSFER

protected static final java.lang.String HA_SESSION_STATE_STATE_TRANSFER
See Also:
Constant Field Values (src)

locks

protected java.util.HashMap locks

appSessions

protected java.util.Hashtable appSessions

lockAppSession

protected java.lang.Object lockAppSession

listeners

protected java.util.Hashtable listeners
Constructor Detail

HASessionStateImpl

public HASessionStateImpl()

HASessionStateImpl

public HASessionStateImpl(java.lang.String sessionStateName,
                          java.lang.String mainHAPartitionName,
                          long beanCleaningDelay)
Method Detail

init

public void init()
          throws java.lang.Exception
Specified by:
init in interface HASessionState (src)
Throws:
java.lang.Exception

bind

protected void bind(java.lang.String jndiName,
                    java.lang.Object who,
                    java.lang.Class classType,
                    javax.naming.Context ctx)
             throws java.lang.Exception
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Specified by:
start in interface HASessionState (src)
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Throws:
java.lang.Exception

getNodeName

public java.lang.String getNodeName()
Description copied from interface: HASessionState (src)
Return the name of this node as used in the computations

Specified by:
getNodeName in interface HASessionState (src)

getCurrentState

public java.io.Serializable getCurrentState()
Description copied from interface: HAPartition.HAPartitionStateTransfer (src)
Called when a new node need to be initialized. This is called on any existing node to determine a current state for this service.

Specified by:
getCurrentState in interface HAPartition.HAPartitionStateTransfer (src)
Returns:
A serializable representation of the state

setCurrentState

public void setCurrentState(java.io.Serializable newState)
Description copied from interface: HAPartition.HAPartitionStateTransfer (src)
This callback method is called when a new service starts on a new node: the state that it should hold is transfered to it through this callback

Specified by:
setCurrentState in interface HAPartition.HAPartitionStateTransfer (src)
Parameters:
newState - The serialized representation of the state of the new service.

purgeState

public void purgeState()

deflate

protected byte[] deflate(java.lang.Object object)
                  throws java.io.IOException
Throws:
java.io.IOException

inflate

protected java.lang.Object inflate(byte[] compressedContent)
                            throws java.io.IOException
Throws:
java.io.IOException

getHashtableForApp

protected java.util.Hashtable getHashtableForApp(java.lang.String appName)

createSession

public void createSession(java.lang.String appName,
                          java.lang.Object keyId)
Description copied from interface: HASessionState (src)
Share a new session state in the sub-partition of this cluster

Specified by:
createSession in interface HASessionState (src)
Parameters:
appName - Application name for which is state is shared
keyId - Key identifier of the state

_createSession

public PackagedSessionImpl (src)  _createSession(java.lang.String appName,
                                          java.lang.Object keyId)

setState

public void setState(java.lang.String appName,
                     java.lang.Object keyId,
                     byte[] state)
              throws java.rmi.RemoteException
Description copied from interface: HASessionState (src)
Modifies a state already shared

Specified by:
setState in interface HASessionState (src)
Parameters:
appName - Application name hosting this state
keyId - Key identifier of the state to modify
state - New state
Throws:
java.rmi.RemoteException

_setState

public void _setState(java.lang.String appName,
                      PackagedSession (src)  session)

getState

public PackagedSession (src)  getState(java.lang.String appName,
                                java.lang.Object keyId)
Description copied from interface: HASessionState (src)
Get a particular state

Specified by:
getState in interface HASessionState (src)
Parameters:
appName - Application hosting the state
keyId - Key identifier of the state
Returns:
The state value

getStateWithOwnership

public PackagedSession (src)  getStateWithOwnership(java.lang.String appName,
                                             java.lang.Object keyId)
                                      throws java.rmi.RemoteException
Description copied from interface: HASessionState (src)
Get a state and, if it is not already the case, takes its ownership (a state is always owned by a node)

Specified by:
getStateWithOwnership in interface HASessionState (src)
Parameters:
appName - Application hosting the state
keyId - Key identifier of the state
Returns:
The state value
Throws:
java.rmi.RemoteException - Thrown if an exception occurs while getting the ownership of the state

localTakeOwnership

public PackagedSession (src)  localTakeOwnership(java.lang.String appName,
                                          java.lang.Object keyId)
                                   throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

_setOwnership

public java.lang.Boolean _setOwnership(java.lang.String appName,
                                       java.lang.Object keyId,
                                       java.lang.String newOwner,
                                       java.lang.Long remoteVersion)

takeOwnership

public void takeOwnership(java.lang.String appName,
                          java.lang.Object keyId)
                   throws java.rmi.RemoteException
Description copied from interface: HASessionState (src)
Take ownership of a state. Each state is owned by a node.

Specified by:
takeOwnership in interface HASessionState (src)
Parameters:
appName - Application hosting the state
keyId - Key identifier of the state
Throws:
java.rmi.RemoteException - Trown if a communication exception occurs while asking other node to get the ownership

removeSession

public void removeSession(java.lang.String appName,
                          java.lang.Object keyId)
Description copied from interface: HASessionState (src)
Remove a session from the sub-partition

Specified by:
removeSession in interface HASessionState (src)
Parameters:
appName - Application hosting the state
keyId - Key identifier of the state

_removeSession

public void _removeSession(java.lang.String appName,
                           java.lang.Object keyId)

subscribe

public void subscribe(java.lang.String appName,
                      HASessionState.HASessionStateListener (src)  listener)
Description copied from interface: HASessionState (src)
Subscribe to receive notifications when objects gets modified on another node.

Specified by:
subscribe in interface HASessionState (src)

unsubscribe

public void unsubscribe(java.lang.String appName,
                        HASessionState.HASessionStateListener (src)  listener)
Specified by:
unsubscribe in interface HASessionState (src)

ownedObjectExternallyModified

public void ownedObjectExternallyModified(java.lang.String appName,
                                          java.lang.Object key,
                                          PackagedSession (src)  oldSession,
                                          PackagedSession (src)  newSession)

getCurrentHAPartition

public HAPartition (src)  getCurrentHAPartition()
Specified by:
getCurrentHAPartition in interface HASessionState (src)

lockExists

protected boolean lockExists(java.lang.String appName,
                             java.lang.Object key)

getLock

protected Mutex getLock(java.lang.String appName,
                        java.lang.Object key)

removeLock

protected void removeLock(java.lang.String appName,
                          java.lang.Object key)