synchronized (sessions)
{
for (Iterator i = txState.getSessionStates().iterator(); i.hasNext(); )
{
SessionTxState sessionState = (SessionTxState)i.next();
// send the messages
for (Iterator j = sessionState.getMsgs().iterator(); j.hasNext(); )
{
JBossMessage message = (JBossMessage)j.next();
if (checkForDuplicates && firstIteration)
{
firstIteration = false;
if (serverPeer.getPersistenceManagerInstance().
referenceExists(message.getMessageID()))
{
// This means the transaction was previously completed...
// we are done here then... no need to even check for ACKs or anything else
log.debug("Transaction " + tx + " was previously completed, ignoring call");
return;
}
}
sendMessage(message, tx, false);
}
// send the acks
// We need to lookup the session in a global map maintained on the server peer. We can't
// just assume it's one of the sessions in the connection. This is because in the case
// of a connection consumer, the message might be delivered through one connection and
// the transaction committed/rolledback through another. ConnectionConsumers suck.
ServerSessionEndpoint session =
serverPeer.getSession(new Integer(sessionState.getSessionId()));
if (session == null)
{
throw new IllegalStateException("Cannot find session with id " +
sessionState.getSessionId());
}
session.acknowledgeTransactionally(sessionState.getAcks(), tx);
}
}
if (trace) { log.trace(this + " processed transaction " + tx); }
}