Package com.arjuna.ats.arjuna
Class AtomicAction
- java.lang.Object
-
- com.arjuna.ats.arjuna.StateManager
-
- com.arjuna.ats.arjuna.coordinator.BasicAction
-
- com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator
-
- com.arjuna.ats.arjuna.AtomicAction
-
- All Implemented Interfaces:
Reapable
- Direct Known Subclasses:
AtomicAction
,EditableAtomicAction
,RecoverAtomicAction
,RecoverConnectableAtomicAction
,TopLevelAction
,Transaction
public class AtomicAction extends TwoPhaseCoordinator
This is a user-level transaction class, unlike BasicAction. AtomicAction takes care of thread-to-action scoping. This is a "one-shot" object, i.e., once terminated, the instance cannot be re-used for another transaction. An instance of this class is a transaction that can be started and terminated (either committed or rolled back). There are also methods to allow participants (AbstractRecords) to be enlisted with the transaction and to associate/disassociate threads with the transaction.- Since:
- JTS 1.0.
- Version:
- $Id: AtomicAction.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected int
_timeout
static int
NO_TIMEOUT
-
Fields inherited from class com.arjuna.ats.arjuna.coordinator.BasicAction
failedList, heuristicList, pendingList, preparedList, readonlyList, savedIntentionList, subordinate, threadStackTraceHistoryList
-
Fields inherited from class com.arjuna.ats.arjuna.StateManager
modifyingActions, objectModel, objectUid, usingActions
-
-
Constructor Summary
Constructors Modifier Constructor Description AtomicAction()
Create a new transaction.protected
AtomicAction(int at)
Create a new transaction of the specified type.AtomicAction(Uid objUid)
AtomicAction constructor with a Uid.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
abort()
Abort (rollback) the transaction.boolean
addThread()
Register the current thread with the transaction.boolean
addThread(java.lang.Thread t)
Register the specified thread with the transaction.int
begin()
Start the transaction running.int
begin(int timeout)
Start the transaction running.int
cancel()
If this method is called and a transaction is not in a status of RUNNING, ABORT_ONLY or COMMITTING then do not call afterCompletion.protected boolean
checkForCurrent()
By default the BasicAction class only allows the termination of a transaction if it's the one currently associated with the thread.int
commit()
Commit the transaction, and have heuristic reporting.int
commit(boolean report_heuristics)
Commit the transaction.int
end(boolean report_heuristics)
int
getTimeout()
boolean
removeThread()
Unregister the current thread from the transaction.boolean
removeThread(java.lang.Thread t)
Unregister the specified thread from the transaction.static boolean
resume(AtomicAction act)
Resume transaction association on the current thread.static AtomicAction
suspend()
Suspend all transaction association from the invoking thread.java.lang.String
type()
The type of the class is used to locate the state of the transaction log in the object store.-
Methods inherited from class com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator
addSynchronization, afterCompletion, afterCompletion, asyncAfterCompletion, beforeCompletion, getDeferredThrowable, getSynchronizations, outputCapturedStackTraces, recordStackTraces, running, start, start
-
Methods inherited from class com.arjuna.ats.arjuna.coordinator.BasicAction
Abort, Abort, abortStatus, activate, activate, activeThreads, add, addChildAction, addChildThread, addChildThread, addRecord, async_prepare, Begin, childTransactions, commitStatus, createStackTraces, criticalEnd, criticalStart, Current, deactivate, destroy, doAbort, doAbort, doCommit, doCommit, doPrepare, End, equals, finalizeInternal, forgetHeuristics, getDeferredThrowables, getHeuristicDecision, getHierarchy, getSavingUid, getStore, hashCode, hierarchyDepth, insertRecord, isAncestor, maintainHeuristics, onePhaseCommit, onePhaseCommit, parent, phase2Abort, phase2Cleanup, phase2Commit, prepare, preparedStatus, preventCommit, removeChildAction, removeChildThread, removeChildThread, restore_state, save_state, setCheckedAction, setHeuristicDecision, status, topLevelAction, topLevelActionUid, toString, typeOfAction, updateHeuristic, updateState
-
Methods inherited from class com.arjuna.ats.arjuna.StateManager
cleanup, createLists, deactivate, deactivate, disable, forgetAction, get_uid, getMutex, getObjectModel, getStoreRoot, loadObjectState, lockMutex, modified, objectType, packHeader, persist, print, rememberAction, setStatus, setupStore, setupStore, setupStore, terminate, tryLockMutex, unlockMutex, unpackHeader
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.arjuna.ats.arjuna.coordinator.Reapable
get_uid, preventCommit
-
-
-
-
Field Detail
-
NO_TIMEOUT
public static final int NO_TIMEOUT
- See Also:
- Constant Field Values
-
_timeout
protected int _timeout
-
-
Constructor Detail
-
AtomicAction
public AtomicAction()
Create a new transaction. If there is already a transaction associated with the thread then this new transaction will be automatically nested. The transaction is *not* running at this point. No timeout is associated with this transaction, i.e., it will not be automatically rolled back by the system.
-
AtomicAction
public AtomicAction(Uid objUid)
AtomicAction constructor with a Uid. This constructor is for recreating an AtomicAction, typically during crash recovery.
-
AtomicAction
protected AtomicAction(int at)
Create a new transaction of the specified type.
-
-
Method Detail
-
begin
public int begin()
Start the transaction running. If the transaction is already running or has terminated, then an error code will be returned. No timeout is associated with the transaction.- Returns:
ActionStatus
indicating outcome.
-
begin
public int begin(int timeout)
Start the transaction running. If the transaction is already running or has terminated, then an error code will be returned.- Parameters:
timeout
- the timeout associated with the transaction. If the transaction is still active when this timeout elapses, the system will automatically roll it back.- Returns:
ActionStatus
indicating outcome.
-
commit
public int commit()
Commit the transaction, and have heuristic reporting. Heuristic reporting via the return code is enabled.- Returns:
ActionStatus
indicating outcome.
-
commit
public int commit(boolean report_heuristics)
Commit the transaction. The report_heuristics parameter can be used to determine whether or not heuristic outcomes are reported. If the transaction has already terminated, or has not begun, then an appropriate error code will be returned.- Returns:
ActionStatus
indicating outcome.
-
abort
public int abort()
Abort (rollback) the transaction. If the transaction has already terminated, or has not been begun, then an appropriate error code will be returned.- Returns:
ActionStatus
indicating outcome.
-
end
public int end(boolean report_heuristics)
- Overrides:
end
in classTwoPhaseCoordinator
-
cancel
public int cancel()
Description copied from class:TwoPhaseCoordinator
If this method is called and a transaction is not in a status of RUNNING, ABORT_ONLY or COMMITTING then do not call afterCompletion. A scenario where this may occur is if during the completion of a previous transaction, a runtime exception is thrown from one of the AbstractRecords methods. RuntimeExceptions are not part of the contract of the API and as such all we can do is leave the transaction alone.- Specified by:
cancel
in interfaceReapable
- Overrides:
cancel
in classTwoPhaseCoordinator
-
getTimeout
public final int getTimeout()
-
type
public java.lang.String type()
The type of the class is used to locate the state of the transaction log in the object store. Overloads BasicAction.type()- Overrides:
type
in classTwoPhaseCoordinator
- Returns:
- a string representation of the hierarchy of the class for storing logs in the transaction object store.
-
addThread
public boolean addThread()
Register the current thread with the transaction. This operation is not affected by the state of the transaction.- Returns:
true
if successful,false
otherwise.
-
addThread
public boolean addThread(java.lang.Thread t)
Register the specified thread with the transaction. This operation is not affected by the state of the transaction.- Returns:
true
if successful,false
otherwise.
-
removeThread
public boolean removeThread()
Unregister the current thread from the transaction. This operation is not affected by the state of the transaction.- Returns:
true
if successful,false
otherwise.
-
removeThread
public boolean removeThread(java.lang.Thread t)
Unregister the specified thread from the transaction. This operation is not affected by the state of the transaction.- Returns:
true
if successful,false
otherwise.
-
suspend
public static final AtomicAction suspend()
Suspend all transaction association from the invoking thread. When this operation returns, the thread will be associated with no transactions. If the current transaction is not an AtomicAction then this method will not suspend.- Returns:
- a handle on the current AtomicAction (if any) so that the thread can later resume association if required.
-
resume
public static final boolean resume(AtomicAction act)
Resume transaction association on the current thread. If the specified transaction is null, then this is the same as doing a suspend. If the current thread is associated with transactions then those associations will be lost.- Parameters:
act
- the transaction to associate. If this is a nested transaction, then the thread will be associated with all of the transactions in the hierarchy.- Returns:
true
if association is successful,false
otherwise.
-
checkForCurrent
protected boolean checkForCurrent()
By default the BasicAction class only allows the termination of a transaction if it's the one currently associated with the thread. We override this here.- Overrides:
checkForCurrent
in classBasicAction
- Returns:
true
to indicate that this transaction can only be terminated by the right thread.
-
-