Package com.arjuna.ats.arjuna
Class StateManager
java.lang.Object
com.arjuna.ats.arjuna.StateManager
- Direct Known Subclasses:
AbstractRecord,BasicAction,Lock,LockManager,StateManagerWrapper
The root of the Arjuna class hierarchy. This class provides state management
facilities than can be automatically used by other classes by inheritance.
- Since:
- JTS 1.0.
- Version:
- $Id: StateManager.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedStateManager(int ot) protectedStateManager(int ot, int om) protectedStateManager(Uid objUid) Create object with specific uid.protectedStateManager(Uid objUid, int ot) protectedStateManager(Uid objUid, int ot, int om) -
Method Summary
Modifier and TypeMethodDescriptionbooleanactivate()This operation activates an object.booleanThis operation activates an object.protected final voidcleanup(boolean fromTerminate) Object cleanup.protected voidbooleanThis operation deactivates a persistent object.booleandeactivate(String rootName) This operation deactivates a persistent object.booleandeactivate(String rootName, boolean commit) This operation deactivates a persistent object.booleandestroy()Destroy the object (e.g., remove its state from the persistent store.) Calls to destroy for volatile objects (ones not maintained within the volatile object store) are ignored, and FALSE is returned.voiddisable()The following function disables recovery for an object by setting the ObjectType to NEITHER (RECOVERABLE or ANDPERSISTENT).protected final booleanforgetAction(BasicAction action, boolean committed, int recordType) Remove action from list of using actions.final Uidget_uid()final longprotected final ReentrantLockgetMutex()intgetStore()final Stringprotected final booleanDo we need to load the object's state?protected final booleanprotected booleanmodified()The object's state is about to be modified, and StateManager should take a snapshot of the state if the object is being used within a transaction.intprotected voidpackHeader(OutputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr) Pack the necessary information for crash recovery.protected final voidpersist()The persist function changes the type of the object from RECOVERABLE to ANDPERSISTENT.voidprint(PrintWriter strm) Print out information about the object.protected final booleanrememberAction(BasicAction action, int recordType, int state) Remember that the specified transaction is using the object.booleanrestore_state(InputObjectState os, int ot) These methods must be provided by a derived class.booleansave_state(OutputObjectState os, int ot) These methods must be used by a derived class.protected final voidsetStatus(int s) protected final voidMake sure the object store is set up, if required.protected voidsetupStore(String rootName) protected voidsetupStore(String rootName, String objectStoreType) Make sure the object store is set up, if required.intstatus()protected voidThe following function checks to see if the object is going out of scope while an action is still running.protected final booleantype()The object's type.protected final booleanprotected voidunpackHeader(InputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr) Unpack the crash recovery state header information and return it.
-
Field Details
-
modifyingActions
-
usingActions
-
objectUid
-
objectModel
protected int objectModel -
synchronizationLock
-
-
Constructor Details
-
StateManager
Create object with specific uid. This constructor is primarily used when recreating an existing object. The object type is set to 'ANDPERSISTENT' this is equivalent to invoking persist in the object constructor. -
StateManager
-
StateManager
-
StateManager
protected StateManager() -
StateManager
protected StateManager(int ot) -
StateManager
protected StateManager(int ot, int om)
-
-
Method Details
-
save_state
These methods must be used by a derived class. They are responsible for packing and unpacking an object's state to/from a state buffer. StateManager calls them at appropriate times during the lifetime of the object, and may then pass the buffer to a persistent object store for saving. If a derived class calls super.save_state then it must be called before packing any other data item.- Returns:
trueon success,falseotherwise.
-
restore_state
These methods must be provided by a derived class. They are responsible for packing and unpacking an object's state to/from a state buffer. StateManager calls them at appropriate times during the lifetime of the object, and may then pass the buffer to a persistent object store for saving. Data items must be unpacked in the same order that they were packed.- Returns:
trueon success,falseotherwise.
-
activate
public boolean activate()This operation activates an object. Activation of an object may entail loading its passive state from the object store and unpacking it into the memory resident form, or it may simply be a no-op. Full activation is only necessary if the object is currently marked as being PASSIVE (that is, the object was constructed as being of type ANDPERSISTENT with an existing uid and has not already been activated). Objects that are not of type ANDPERSISTENT or are persistent but have not yet been saved in an object store (so-called new persistent objects) are unaffected by this function. Returns false if PASSIVE object cannot be loaded from object store, true otherwise. The root of the object store is taken asnull.- Returns:
trueon success,falseotherwise.- See Also:
-
activate
This operation activates an object. Activation of an object may entail loading its passive state from the object store and unpacking it into the memory resident form, or it may simply be a no-op. Full activation is only necessary if the object is currently marked as being PASSIVE (that is, the object was constructed as being of type ANDPERSISTENT with an existing uid and has not already been activated). Objects that are not of type ANDPERSISTENT or are persistent but have not yet been saved in an object store (so-called new persistent objects) are unaffected by this function. Returns false if PASSIVE object cannot be loaded from object store, true otherwise.- Returns:
trueon success,falseotherwise.- See Also:
-
deactivate
public boolean deactivate()This operation deactivates a persistent object. It behaves in a similar manner to the activate operation, but has an extra argument which defines whether the object's state should be committed or written as a shadow. The root of the object store isnull. It is assumed that this is being called during a transaction commit.- Returns:
trueon success,falseotherwise.
-
deactivate
This operation deactivates a persistent object. It behaves in a similar manner to the activate operation, but has an extra argument which defines whether the object's state should be commited now or not. It is assumed that this is being called during a transaction commit.- Returns:
trueon success,falseotherwise.
-
deactivate
This operation deactivates a persistent object. It behaves in a similar manner to the activate operation, but has an extra argument which defines whether the object's state should be commited now or not.- Returns:
trueon success,falseotherwise.
-
status
public int status()- Returns:
- the object's current status (active, passive, ...)
-
objectType
public int objectType()- Returns:
- the type of the object (persistent, recoverable, ...)
-
getObjectModel
public int getObjectModel() -
get_uid
- Returns:
- the object's unique identifier.
-
getCreationTimeMillis
public final long getCreationTimeMillis()- Returns:
- the time the object was created in milliseconds since midnight, January 1, 1970 UTC
- See Also:
-
destroy
public boolean destroy()Destroy the object (e.g., remove its state from the persistent store.) Calls to destroy for volatile objects (ones not maintained within the volatile object store) are ignored, and FALSE is returned.- Returns:
trueon success,falseotherwise.
-
disable
public void disable()The following function disables recovery for an object by setting the ObjectType to NEITHER (RECOVERABLE or ANDPERSISTENT). The value of this variable is checked in the modified operation so that no recovery information is created if myType is set to NEITHER. -
print
Print out information about the object. -
type
The object's type. Derived classes should override this to reflect their type structure. Typically this string is used for locating the object state in an object store, and reflects the hierarchy structure of the object. -
getStoreRoot
- Returns:
- the root of the object store this instance will use if it has to save the state of the object to storage.
-
getStore
- Returns:
- the object store this instance will used if it has to save the state of the object to storage.
-
packHeader
protected void packHeader(OutputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr) throws IOException Pack the necessary information for crash recovery.- Throws:
IOException- Since:
- JTS 2.1.
-
unpackHeader
protected void unpackHeader(InputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr) throws IOException Unpack the crash recovery state header information and return it.- Parameters:
os- the identity of the transaction that last caused the state to be written to the object store.- Throws:
IOException- Since:
- JTS 2.1.
-
terminate
protected void terminate()The following function checks to see if the object is going out of scope while an action is still running. -
setStatus
protected final void setStatus(int s) -
modified
protected boolean modified()The object's state is about to be modified, and StateManager should take a snapshot of the state if the object is being used within a transaction.- Returns:
trueon success,falseotherwise.
-
persist
protected final void persist()The persist function changes the type of the object from RECOVERABLE to ANDPERSISTENT. No changes are made unless the status of the object is ACTIVE, so it is not possible to change the type of the object if it has been modified. -
cleanup
protected final void cleanup(boolean fromTerminate) Object cleanup. Attempt sane cleanup when object is deleted. Handle perverse cases where multiple actions are still active as object dies.- Parameters:
fromTerminate- indicates whether this method is being called from theterminatemethod, or from elsewhere.- See Also:
-
setupStore
protected final void setupStore()Make sure the object store is set up, if required. The root of the object store is assumed to benull. -
setupStore
-
setupStore
Make sure the object store is set up, if required.- Parameters:
rootName- indicates the root of the object store.
-
loadObjectState
protected final boolean loadObjectState()Do we need to load the object's state?- Returns:
trueif the object state should be loaded,falseotherwise.
-
forgetAction
Remove action from list of using actions. If the action list empties reset state to PASSIVE. The second param tells why the action should be forgotten. This aids in resetting the state correctly. -
rememberAction
Remember that the specified transaction is using the object. -
getMutex
- Returns:
- the mutex object used to lock this object.
- Since:
- JTS 2.1.
-
lockMutex
protected final boolean lockMutex()- Returns:
- the result of the attempt to lock this object.
- Since:
- JTS 2.1.
-
unlockMutex
protected final boolean unlockMutex()- Returns:
- the result of the attempt to unlock this object.
- Since:
- JTS 2.1.
-
tryLockMutex
protected final boolean tryLockMutex()- Returns:
trueif the object was locked,falseif the attempt would cause the thread to block.- Since:
- JTS 2.1.
-
createLists
protected void createLists()
-