Package com.arjuna.ats.arjuna
Class StateManager
- java.lang.Object
-
- com.arjuna.ats.arjuna.StateManager
-
- Direct Known Subclasses:
AbstractRecord,BasicAction,Lock,LockManager,StateManagerWrapper
public class StateManager extends Object
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 Modifier and Type Field Description protected HashtablemodifyingActionsprotected intobjectModelprotected UidobjectUidprotected HashtableusingActions
-
Constructor Summary
Constructors Modifier Constructor Description protectedStateManager()protectedStateManager(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanactivate()This operation activates an object.booleanactivate(String rootName)This operation activates an object.protected voidcleanup(boolean fromTerminate)Object cleanup.protected voidcreateLists()booleandeactivate()This 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 booleanforgetAction(BasicAction action, boolean committed, int recordType)Remove action from list of using actions.Uidget_uid()protected ReentrantLockgetMutex()intgetObjectModel()ParticipantStoregetStore()StringgetStoreRoot()protected booleanloadObjectState()Do we need to load the object's state?protected booleanlockMutex()protected 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.intobjectType()protected voidpackHeader(OutputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr)Pack the necessary information for crash recovery.protected voidpersist()The persist function changes the type of the object from RECOVERABLE to ANDPERSISTENT.voidprint(PrintWriter strm)Print out information about the object.protected 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 voidsetStatus(int s)protected voidsetupStore()Make 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 voidterminate()The following function checks to see if the object is going out of scope while an action is still running.protected booleantryLockMutex()Stringtype()The object's type.protected booleanunlockMutex()protected voidunpackHeader(InputObjectState os, com.arjuna.ats.internal.arjuna.Header hdr)Unpack the crash recovery state header information and return it.
-
-
-
Constructor Detail
-
StateManager
protected StateManager(Uid objUid)
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
protected StateManager(Uid objUid, int ot)
-
StateManager
protected StateManager(Uid objUid, int ot, int om)
-
StateManager
protected StateManager()
-
StateManager
protected StateManager(int ot)
-
StateManager
protected StateManager(int ot, int om)
-
-
Method Detail
-
save_state
public boolean save_state(OutputObjectState os, int ot)
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
public boolean restore_state(InputObjectState os, int ot)
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:
ObjectStore
-
activate
public boolean activate(String rootName)
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:
ObjectStore
-
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
public boolean deactivate(String rootName)
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
public boolean deactivate(String rootName, boolean commit)
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
public final Uid get_uid()
- Returns:
- the object's unique identifier.
-
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
public void print(PrintWriter strm)
Print out information about the object.
-
type
public String 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
public final String 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
public ParticipantStore 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:
terminate()
-
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
protected void setupStore(String rootName)
-
setupStore
protected void setupStore(String rootName, String objectStoreType)
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
protected final boolean forgetAction(BasicAction action, boolean committed, int recordType)
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
protected final boolean rememberAction(BasicAction action, int recordType, int state)
Remember that the specified transaction is using the object.
-
getMutex
protected final ReentrantLock 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()
-
-