}
}
TransactionWork getTransactionWork2(List plist, HashMap cmap,
HashMap sToCmap) {
TransactionWork txnWork = new TransactionWork();
// iterate over messages produced in this transaction
// NB should we be checking for persistent messages?
for (int i = 0; plist != null && i < plist.size(); i++) {
SysMessageID sysid = (SysMessageID) plist.get(i);
PacketReference ref = Destination.get(sysid);
if (ref == null) {
logger.log(Logger.ERROR,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"transacted message removed too early " + sysid);
continue;
}
try {
if (ref.isPersistent()) {
TransactionWorkMessage txnWorkMessage = new TransactionWorkMessage();
Destination dest = ref.getDestination();
txnWorkMessage.setDestUID(dest.getDestinationUID());
txnWorkMessage.setPacketReference(ref);
txnWork.addMesage(txnWorkMessage);
}
} catch (Exception ex) {
logger.logStack((BrokerStateHandler.shuttingDown ? Logger.DEBUG
: Logger.ERROR),
BrokerResources.E_INTERNAL_BROKER_ERROR,
"unable to log transaction message " + sysid, ex);
}
}
// iterate over messages consumed in this transaction
if (cmap != null && cmap.size() > 0) {
Iterator itr = cmap.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
SysMessageID sysid = (SysMessageID) entry.getKey();
List interests = (List) entry.getValue();
if (sysid == null)
continue;
PacketReference ref = Destination.get(sysid);
if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
// already been deleted .. ignore
continue;
}
// Do we want to store acknowledgements for remote brokers?
// If this is a local transaction, then all acks should be local.
// If this is a cluster transaction, then acks for remote messages
// will be forwarded to remote brokers as part of the protocol.
// The cluster txn should only need op store the addresses of the brokers involved.
if(!ref.isLocal())
{
continue;
}
Destination dst = Destination.getDestination(ref
.getDestinationUID());
// A bit unlikely, but a message may have been consumed multiple
// times in the same transaction by different consumers
// - hence the list.
for (int i = 0; i < interests.size(); i++) {
ConsumerUID intid = (ConsumerUID) interests.get(i);
ConsumerUID sid = (ConsumerUID) sToCmap.get(intid);
if (sid == null)
sid = intid;
try {
// ignore non-durable subscriber
if (!dst.isQueue() && !sid.shouldStore()) {
continue;
}
if (ref.isPersistent()) {
TransactionWorkMessageAck ack = new TransactionWorkMessageAck();
ack.setConsumerID(sid);
ack.setDest(dst.getDestinationUID());
ack.setSysMessageID(sysid);
txnWork.addMessageAcknowledgement(ack);
}
} catch (Exception ex) {
logger.logStack(Logger.ERROR,