Class 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 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

      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 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 class TwoPhaseCoordinator
    • 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 interface Reapable
      Overrides:
      cancel in class TwoPhaseCoordinator
    • getTimeout

      public final int getTimeout()
    • type

      public 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 class TwoPhaseCoordinator
      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(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(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 class BasicAction
      Returns:
      true to indicate that this transaction can only be terminated by the right thread.