public synchronized void xaFailed(final Xid xid) throws Exception { if (tx != null) { final String msg = "Cannot start, session is already doing work in a transaction " + tx.getXid(); throw new HornetQXAException(XAException.XAER_PROTO, msg); } else { tx = newTransaction(xid); tx.markAsRollbackOnly( new HornetQException("Can't commit as a Failover happened during the operation")); if (isTrace) { HornetQServerLogger.LOGGER.trace("xastart into tx= " + tx); } boolean added = resourceManager.putTransaction(xid, tx); if (!added) { final String msg = "Cannot start, there is already a xid " + tx.getXid(); throw new HornetQXAException(XAException.XAER_DUPID, msg); } } }
public synchronized void xaStart(final Xid xid) throws Exception { if (tx != null) { HornetQServerLogger.LOGGER.xidReplacedOnXStart(tx.getXid().toString(), xid.toString()); try { if (tx.getState() != Transaction.State.PREPARED) { // we don't want to rollback anything prepared here if (tx.getXid() != null) { resourceManager.removeTransaction(tx.getXid()); } tx.rollback(); } } catch (Exception e) { HornetQServerLogger.LOGGER.debug( "An exception happened while we tried to debug the previous tx, we can ignore this exception", e); } } tx = newTransaction(xid); if (isTrace) { HornetQServerLogger.LOGGER.trace("xastart into tx= " + tx); } boolean added = resourceManager.putTransaction(xid, tx); if (!added) { final String msg = "Cannot start, there is already a xid " + tx.getXid(); throw new HornetQXAException(XAException.XAER_DUPID, msg); } }
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); } } } }
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); } } } }
public synchronized void xaStart(final Xid xid) throws Exception { if (tx != null) { final String msg = "Cannot start, session is already doing work in a transaction " + tx.getXid(); throw new HornetQXAException(XAException.XAER_PROTO, msg); } else { tx = newTransaction(xid); if (isTrace) { HornetQLogger.LOGGER.trace("xastart into tx= " + tx); } boolean added = resourceManager.putTransaction(xid, tx); if (!added) { final String msg = "Cannot start, there is already a xid " + tx.getXid(); throw new HornetQXAException(XAException.XAER_DUPID, msg); } } }