Object currentXid = sessionState.getCurrentTxId();
// Sanity check
if (currentXid == null)
{
throw new MessagingXAException(XAException.XAER_RMFAIL, "Current xid is not set");
}
if (sessionState.getCurrentTxId() instanceof LocalTx)
{
convertTx = true;
if (trace) { log.trace("Converting local tx into global tx branch"); }
}
//TODO why do we need this synchronized block?
synchronized (this)
{
switch (flags)
{
case TMNOFLAGS :
if (convertTx)
{
// If I commit/rollback the tx, then there is a short period of time between the
// AS (or whoever) calling commit on the tx and calling start to enrolling the
// session in a new tx. If the session has any listeners then in that period,
// messages can be received asychronously but we want them to be received in the
// context of a tx, so we convert.
// Also for an transacted delivery in a MDB we need to do this as discussed
// in fallbackToLocalTx()
setCurrentTransactionId(rm.convertTx((LocalTx)sessionState.getCurrentTxId(), xid));
}
else
{
setCurrentTransactionId(rm.startTx(xid));
}
break;
case TMJOIN :
if(convertTx)
{
setCurrentTransactionId(rm.convertOnJoinTx((LocalTx)sessionState.getCurrentTxId(), xid));
}
else
{
setCurrentTransactionId(rm.joinTx(xid));
}
break;
case TMRESUME :
if(convertTx)
{
setCurrentTransactionId(rm.convertOnJoinTx((LocalTx)sessionState.getCurrentTxId(), xid));
}
else
{
setCurrentTransactionId(rm.resumeTx(xid));
}
break;
default:
throw new MessagingXAException(XAException.XAER_PROTO, "Invalid flags: " + flags);
}
}
}