{
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)
{
HornetQServerLogger.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)
{
HornetQServerLogger.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)
{
HornetQServerLogger.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)
{
HornetQServerLogger.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);