Пример #1
0
  /**
   * Suspend all transaction association from the invoking thread. When this operation returns, the
   * thread will be associated with no transactions.
   *
   * <p>If the current transaction is not an AtomicAction then this method will not suspend.
   *
   * @return a handle on the current AtomicAction (if any) so that the thread can later resume
   *     association if required.
   */
  public static final AtomicAction suspend() {
    BasicAction curr = ThreadActionData.currentAction();

    if (curr != null) {
      if (curr instanceof AtomicAction) ThreadActionData.purgeActions();
      else {
        tsLogger.i18NLogger.warn_ats_atomicaction_1(curr.toString());

        curr = null;
      }
    }

    return (AtomicAction) curr;
  }
Пример #2
0
  /**
   * 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.
   *
   * @param 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.
   * @return <code>true</code> if association is successful, <code>false</code> otherwise.
   */
  public static final boolean resume(AtomicAction act) {
    if (act == null) {
      suspend();
    } else ThreadActionData.restoreActions(act);

    return true;
  }
Пример #3
0
  /**
   * Unregister the specified thread from the transaction. This operation is not affected by the
   * state of the transaction.
   *
   * @return <code>true</code> if successful, <code>false</code> otherwise.
   */
  public boolean removeThread(Thread t) {
    if (t != null) {
      ThreadActionData.purgeAction(this, t);
      return true;
    }

    return false;
  }
Пример #4
0
  /**
   * Register the specified thread with the transaction. This operation is not affected by the state
   * of the transaction.
   *
   * @return <code>true</code> if successful, <code>false</code> otherwise.
   */
  public boolean addThread(Thread t) {
    if (t != null) {
      ThreadActionData.pushAction(this);
      return true;
    }

    return false;
  }
Пример #5
0
  /**
   * Abort (rollback) the transaction.
   *
   * <p>If the transaction has already terminated, or has not been begun, then an appropriate error
   * code will be returned.
   *
   * @return <code>ActionStatus</code> indicating outcome.
   */
  public int abort() {
    int status = super.cancel();

    /*
     * Now remove this thread from the action state.
     */

    ThreadActionData.popAction();

    TransactionReaper.transactionReaper().remove(this);

    return status;
  }
Пример #6
0
  /**
   * Commit the transaction. The report_heuristics parameter can be used to determine whether or not
   * heuristic outcomes are reported.
   *
   * <p>If the transaction has already terminated, or has not begun, then an appropriate error code
   * will be returned.
   *
   * @return <code>ActionStatus</code> indicating outcome.
   */
  public int commit(boolean report_heuristics) {
    int status = super.end(report_heuristics);

    /*
     * Now remove this thread from the action state.
     */

    ThreadActionData.popAction();

    TransactionReaper.transactionReaper().remove(this);

    return status;
  }
Пример #7
0
  /**
   * Start the transaction running.
   *
   * <p>If the transaction is already running or has terminated, then an error code will be
   * returned.
   *
   * @param timeout the timeout associated with the transaction. If the transaction is still active
   *     when this timeout elapses, the system will automatically roll it back.
   * @return <code>ActionStatus</code> indicating outcome.
   */
  public int begin(int timeout) {
    int status = super.start();

    if (status == ActionStatus.RUNNING) {
      /*
       * Now do thread/action tracking.
       */

      ThreadActionData.pushAction(this);

      _timeout = timeout;

      if (_timeout == 0) _timeout = TxControl.getDefaultTimeout();

      if (_timeout > 0) TransactionReaper.transactionReaper().insert(this, _timeout);
    }

    return status;
  }