}
public Object handlePreDeliver(Invocation invocation) throws Throwable
{
MethodInvocation mi = (MethodInvocation)invocation;
SessionState state = getState(invocation);
int ackMode = state.getAcknowledgeMode();
Object[] args = mi.getArguments();
DeliveryInfo info = (DeliveryInfo)args[0];
if (ackMode == Session.CLIENT_ACKNOWLEDGE)
{
// We collect acknowledgments in the list
if (trace) { log.trace(this + " added to CLIENT_ACKNOWLEDGE list delivery " + info); }
// Sanity check
if (info.getConnectionConsumerSession() != null)
{
throw new IllegalStateException(
"CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
}
state.getClientAckList().add(info);
}
else if (ackMode == Session.AUTO_ACKNOWLEDGE)
{
// We collect the single acknowledgement in the state.
if (trace) { log.trace(this + " added " + info + " to session state"); }
state.setAutoAckInfo(info);
}
else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
{
if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
state.getClientAckList().add(info);
//Also set here - this would be used for recovery in a message listener
state.setAutoAckInfo(info);
}
else
{
Object txID = state.getCurrentTxId();
if (txID != null)
{
// the session is non-XA and transacted, or XA and enrolled in a global transaction. An
// XA session that has not been enrolled in a global transaction behaves as a
// transacted session.
ConnectionState connState = (ConnectionState)state.getParent();
if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }
// If the ack is for a delivery that came through via a connection consumer then we use
// the connectionConsumer session as the session id, otherwise we use this sessions'
// session ID
ClientSessionDelegate connectionConsumerDelegate =
(ClientSessionDelegate)info.getConnectionConsumerSession();
int sessionId = connectionConsumerDelegate != null ?
connectionConsumerDelegate.getID() : state.getSessionID();
connState.getResourceManager().addAck(txID, sessionId, info);
}
}