示例#1
0
  public synchronized void xaPrepare(final Xid xid) throws Exception {
    if (tx != null && tx.getXid().equals(xid)) {
      final String msg =
          "Cannot commit, session is currently doing work in a transaction " + tx.getXid();

      throw new HornetQXAException(XAException.XAER_PROTO, msg);
    } else {
      Transaction theTx = resourceManager.getTransaction(xid);

      if (isTrace) {
        HornetQLogger.LOGGER.trace("xaprepare into " + ", xid=" + xid + ", tx= " + tx);
      }

      if (theTx == null) {
        final String msg = "Cannot find xid in resource manager: " + xid;

        throw new HornetQXAException(XAException.XAER_NOTA, msg);
      } else {
        if (theTx.getState() == Transaction.State.SUSPENDED) {
          throw new HornetQXAException(
              XAException.XAER_PROTO, "Cannot prepare transaction, it is suspended " + xid);
        } else if (theTx.getState() == Transaction.State.PREPARED) {
          HornetQLogger.LOGGER.info("ignoring prepare on xid as already called :" + xid);
        } else {
          theTx.prepare();
        }
      }
    }
  }
示例#2
0
  public synchronized void xaResume(final Xid xid) throws Exception {
    if (tx != null) {
      final String msg =
          "Cannot resume, session is currently doing work in a transaction " + tx.getXid();

      throw new HornetQXAException(XAException.XAER_PROTO, msg);
    } else {
      Transaction theTx = resourceManager.getTransaction(xid);

      if (theTx == null) {
        final String msg = "Cannot find xid in resource manager: " + xid;

        throw new HornetQXAException(XAException.XAER_NOTA, msg);
      } else {
        if (theTx.getState() != Transaction.State.SUSPENDED) {
          throw new HornetQXAException(
              XAException.XAER_PROTO, "Cannot resume transaction, it is not suspended " + xid);
        } else {
          tx = theTx;

          tx.resume();
        }
      }
    }
  }
示例#3
0
  public synchronized void xaJoin(final Xid xid) throws Exception {
    Transaction theTx = resourceManager.getTransaction(xid);

    if (theTx == null) {
      final String msg = "Cannot find xid in resource manager: " + xid;

      throw new HornetQXAException(XAException.XAER_NOTA, msg);
    } else {
      if (theTx.getState() == Transaction.State.SUSPENDED) {
        throw new HornetQXAException(
            XAException.XAER_PROTO, "Cannot join tx, it is suspended " + xid);
      } else {
        tx = theTx;
      }
    }
  }
示例#4
0
  public synchronized void xaEnd(final Xid xid) throws Exception {
    if (tx != null && tx.getXid().equals(xid)) {
      if (tx.getState() == Transaction.State.SUSPENDED) {
        final String msg = "Cannot end, transaction is suspended";

        throw new HornetQXAException(XAException.XAER_PROTO, msg);
      } else if (tx.getState() == Transaction.State.ROLLEDBACK) {
        final String msg = "Cannot end, transaction is rolled back";

        tx = null;

        throw new HornetQXAException(XAException.XAER_PROTO, msg);
      } else {
        tx = null;
      }
    } else {
      // It's also legal for the TM to call end for a Xid in the suspended
      // state
      // See JTA 1.1 spec 3.4.4 - state diagram
      // Although in practice TMs rarely do this.
      Transaction theTx = resourceManager.getTransaction(xid);

      if (theTx == null) {
        final String msg = "Cannot find suspended transaction to end " + xid;

        throw new HornetQXAException(XAException.XAER_NOTA, msg);
      } else {
        if (theTx.getState() != Transaction.State.SUSPENDED) {
          final String msg = "Transaction is not suspended " + xid;

          throw new HornetQXAException(XAException.XAER_PROTO, msg);
        } else {
          theTx.resume();
        }
      }
    }
  }