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
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 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, synchronizationLock, usingActions
-
Constructor Summary
ModifierConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionint
abort()
Abort (rollback) the transaction.boolean
Register the current thread with the transaction.boolean
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
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) final int
boolean
Unregister the current thread from the transaction.boolean
Unregister the specified thread from the transaction.static final boolean
resume
(AtomicAction act) Resume transaction association on the current thread.static final AtomicAction
suspend()
Suspend all transaction association from the invoking thread.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, getCreationTimeMillis, 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 Details
-
NO_TIMEOUT
public static final int NO_TIMEOUT- See Also:
-
_timeout
protected int _timeout
-
-
Constructor Details
-
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
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 Details
-
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
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
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
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
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
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.
-