public List handleTransaction(IMQConnection con, TransactionUID tid,
SysMessageID[] ids, ConsumerUID[] cids)
throws BrokerException {
for (int i=0; i < ids.length; i ++) {
Consumer consumer = null;
try {
// lookup the session by consumerUID
Session s = Session.getSession(cids[i]);
// look up the consumer by consumerUID
consumer = Consumer.getConsumer(cids[i]);
if (consumer == null) {
throw new BrokerException(
Globals.getBrokerResources().getKString(
BrokerResources.I_ACK_FAILED_NO_CONSUMER, cids[i]), Status.NOT_FOUND);
}
// try and find the stored consumerUID
ConsumerUID sid = consumer.getStoredConsumerUID();
// if we still dont have a session, attempt to find one
if (s == null) {
SessionUID suid = consumer.getSessionUID();
s = Session.getSession(suid);
}
if (s == null) {
if (BrokerStateHandler.shutdownStarted)
throw new BrokerException(
BrokerResources.I_ACK_FAILED_BROKER_SHUTDOWN);
throw new BrokerException("Internal Error: Unable to complete processing transaction:"
+ " Unknown consumer/session " + cids[i]);
}
if (DEBUG) {
logger.log(logger.INFO, "handleTransaction.addAck["+i+", "+ids.length+"]:tid="+tid+
", sysid="+ids[i]+", cid="+cids[i]+", sid="+sid+" on connection "+con);
}
boolean isxa = translist.addAcknowledgement(tid, ids[i], cids[i], sid);
BrokerAddress addr = s.acknowledgeInTransaction(cids[i], ids[i], tid, isxa);
if (addr != null && addr != Globals.getMyAddress()) {
translist.setAckBrokerAddress(tid, ids[i], cids[i], addr);
}
if (fi.FAULT_INJECTION) {
if (fi.checkFault(fi.FAULT_TXN_ACK_1_5, null)) {
fi.unsetFault(fi.FAULT_TXN_ACK_1_5);
TransactionAckExistException tae = new TransactionAckExistException("FAULT:"+fi.FAULT_TXN_ACK_1_5, Status.GONE);
tae.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
tae.setRemote(true);
consumer.recreationRequested();
throw tae;
}
}
} catch (Exception ex) {
String emsg = "["+ids[i]+", "+cids[i] + "]TUID="+tid;
if ((ex instanceof BrokerException) &&
((BrokerException)ex).getStatusCode() != Status.ERROR) {
logger.log(Logger.WARNING , Globals.getBrokerResources().getKString(
BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
} else {
logger.log(Logger.ERROR , Globals.getBrokerResources().getKString(
BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
}
int state = -1;
JMQXid xid = null;
try {
TransactionState ts = translist.retrieveState(tid);
if (ts != null) {
state = ts.getState();
xid = ts.getXid();
}
translist.updateState(tid, TransactionState.FAILED, true);
} catch (Exception e) {
if (!(e instanceof UnknownTransactionException)) {
String args[] = { TransactionState.toString(state),
TransactionState.toString(TransactionState.FAILED),
tid.toString(), (xid == null ? "null": xid.toString()) };
logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(
BrokerResources.W_UPDATE_TRAN_STATE_FAIL, args));
}
}
if (ex instanceof TransactionAckExistException) {
PacketReference ref = Destination.get(ids[i]);
if (ref != null && (ref.isOverrided() || ref.isOverriding())) {
((BrokerException)ex).overrideStatusCode(Status.GONE);
((BrokerException)ex).setRemoteConsumerUIDs(
String.valueOf(cids[i].longValue()));
((BrokerException)ex).setRemote(true);
consumer.recreationRequested();
}
}
if (ex instanceof BrokerException) throw (BrokerException)ex;
throw new BrokerException("Internal Error: Unable to " +