Esempio n. 1
0
  public synchronized void xaRollback(final Xid xid) throws Exception {
    if (tx != null && tx.getXid().equals(xid)) {
      final String msg =
          "Cannot roll back, session is currently doing work in a transaction " + tx.getXid();

      throw new HornetQXAException(XAException.XAER_PROTO, msg);
    } else {
      Transaction theTx = resourceManager.removeTransaction(xid);
      if (isTrace) {
        HornetQLogger.LOGGER.trace("xarollback into " + theTx);
      }

      if (theTx == null) {
        // checked heuristic committed transactions
        if (resourceManager.getHeuristicCommittedTransactions().contains(xid)) {
          throw new HornetQXAException(
              XAException.XA_HEURCOM, "transaction has ben heuristically committed: " + xid);
        }
        // checked heuristic rolled back transactions
        else if (resourceManager.getHeuristicRolledbackTransactions().contains(xid)) {
          throw new HornetQXAException(
              XAException.XA_HEURRB, "transaction has ben heuristically rolled back: " + xid);
        } else {
          if (isTrace) {
            HornetQLogger.LOGGER.trace(
                "xarollback into " + theTx + ", xid=" + xid + " forcing a rollback regular");
          }

          try {
            // jbpapp-8845
            // This could have happened because the TX timed out,
            // at this point we would be better on rolling back this session as a way to prevent
            // consumers from holding their messages
            this.rollback(false);
          } catch (Exception e) {
            HornetQLogger.LOGGER.warn(e.getMessage(), e);
          }

          throw new HornetQXAException(
              XAException.XAER_NOTA, "Cannot find xid in resource manager: " + xid);
        }
      } else {
        if (theTx.getState() == Transaction.State.SUSPENDED) {
          if (isTrace) {
            HornetQLogger.LOGGER.trace(
                "xarollback into " + theTx + " sending tx back as it was suspended");
          }

          // Put it back
          resourceManager.putTransaction(xid, tx);

          throw new HornetQXAException(
              XAException.XAER_PROTO, "Cannot rollback transaction, it is suspended " + xid);
        } else {
          doRollback(false, false, theTx);
        }
      }
    }
  }
Esempio n. 2
0
  public List<Xid> xaGetInDoubtXids() {
    List<Xid> xids = new ArrayList<Xid>();

    xids.addAll(resourceManager.getPreparedTransactions());
    xids.addAll(resourceManager.getHeuristicCommittedTransactions());
    xids.addAll(resourceManager.getHeuristicRolledbackTransactions());

    return xids;
  }
Esempio n. 3
0
  public synchronized void xaCommit(final Xid xid, final boolean onePhase) throws Exception {

    if (tx != null && tx.getXid().equals(xid)) {
      final String msg =
          "Cannot commit, session is currently doing work in transaction " + tx.getXid();

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

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

      if (theTx == null) {
        // checked heuristic committed transactions
        if (resourceManager.getHeuristicCommittedTransactions().contains(xid)) {
          throw new HornetQXAException(
              XAException.XA_HEURCOM, "transaction has been heuristically committed: " + xid);
        }
        // checked heuristic rolled back transactions
        else if (resourceManager.getHeuristicRolledbackTransactions().contains(xid)) {
          throw new HornetQXAException(
              XAException.XA_HEURRB, "transaction has been heuristically rolled back: " + xid);
        } else {
          if (isTrace) {
            HornetQLogger.LOGGER.trace(
                "XAcommit into " + theTx + ", xid=" + xid + " cannot find it");
          }

          throw new HornetQXAException(
              XAException.XAER_NOTA, "Cannot find xid in resource manager: " + xid);
        }
      } else {
        if (theTx.getState() == Transaction.State.SUSPENDED) {
          // Put it back
          resourceManager.putTransaction(xid, theTx);

          throw new HornetQXAException(
              XAException.XAER_PROTO, "Cannot commit transaction, it is suspended " + xid);
        } else {
          theTx.commit(onePhase);
        }
      }
    }
  }