use of com.sun.messaging.jmq.jmsserver.core.PacketReference in project openmq by eclipse-ee4j.
the class TransactionHandler method updateRefsState.
// called from redeliverUnacked for rollback
private void updateRefsState(ConsumerUID storedCuid, SortedSet refs, boolean redeliver, List updatedRefs, TransactionUID tid) {
PacketReference ref = null;
Iterator itr = refs.iterator();
while (itr.hasNext()) {
try {
ref = (PacketReference) itr.next();
if (updatedRefs.contains(ref)) {
continue;
}
if (redeliver) {
ref.consumed(storedCuid, false, false);
} else {
ref.removeDelivered(storedCuid, false);
}
updatedRefs.add(ref);
} catch (Exception ex) {
Object[] args = { "[" + ref + ", " + storedCuid + "]", tid, ex.getMessage() };
logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_UNABLE_UPDATE_REF_STATE_ON_ROLLBACK, args), ex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.PacketReference in project openmq by eclipse-ee4j.
the class TransactionHandler method sortPreprocessRetrievedMessages.
private HashMap sortPreprocessRetrievedMessages(Map cmap, Map sToCmap, boolean processActiveConsumers, int maxRollbacks, boolean dmqOnMaxRollbacks, TransactionUID tid) throws BrokerException {
HashMap sendMap = new HashMap();
// loop through the transaction ack list
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();
// CANT just pull from connection
if (sysid == null) {
continue;
}
PacketReference ref = DL.get(null, sysid, false);
if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
// already been deleted .. ignore
if (DEBUG) {
logger.log(logger.INFO, "redeliverUnacked:tid=" + tid + ": ref=" + ref + " already deleted");
}
continue;
}
if (ref.isOverrided()) {
continue;
}
// now get the interests and stick each message
// in a list specific to the consumer
// the list is automatically sorted
List interests = (List) entry.getValue();
for (int i = 0; i < interests.size(); i++) {
ConsumerUID intid = (ConsumerUID) interests.get(i);
ConsumerUID stored = (ConsumerUID) sToCmap.get(intid);
if (stored == null) {
stored = intid;
}
if (processActiveConsumers && !dmqOnMaxRollbacks) {
Consumer cs = Consumer.getConsumer(intid);
if (cs != null) {
if (!cs.addRollbackCnt(ref.getSysMessageID(), maxRollbacks)) {
Object[] args = { ref, cs, tid };
String emsg = br.getKString(br.X_MAX_ROLLBACKS_MSG_NO_ROLLBACK, args);
logger.log(logger.ERROR, emsg);
throw new MaxConsecutiveRollbackException(emsg);
}
}
}
SortedSet ss = (SortedSet) sendMap.get(intid);
if (ss == null) {
ss = new TreeSet(new RefCompare());
sendMap.put(intid, ss);
}
ref.removeInDelivery(stored);
ss.add(ref);
}
}
}
return sendMap;
}
use of com.sun.messaging.jmq.jmsserver.core.PacketReference in project openmq by eclipse-ee4j.
the class TransactionHandler method retrieveConsumedRemoteMessages.
private HashMap[] retrieveConsumedRemoteMessages(TransactionList translist, TransactionUID id, boolean checkOnly) throws BrokerException {
HashMap mcmap = translist.retrieveConsumedMessages(id);
HashMap sToCmap = translist.retrieveStoredConsumerUIDs(id);
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "retrieveConsumedRemoteMessages(" + translist + ",TID=" + id + ") retrieveConsumedMessages: " + mcmap);
}
if (mcmap == null || mcmap.size() == 0) {
return null;
}
HashMap[] rets = new HashMap[2];
HashMap<BrokerAddress, ArrayList[]> bmmap = new HashMap<>();
HashMap<TransactionBroker, ArrayList<TransactionAcknowledgement>> tbmmap = new HashMap<>();
ArrayList[] bmcll = null;
ArrayList<TransactionAcknowledgement> tbmcl = null;
boolean hasRemote = false;
BrokerAddress myba = Globals.getMyAddress();
UID tranpid = translist.getPartitionedStore().getPartitionID();
UID refpid = null;
ConsumerUID cuid = null, scuid = null;
TransactionAcknowledgement ta = null;
Iterator<Map.Entry> itr = mcmap.entrySet().iterator();
Map.Entry pair = null;
while (itr.hasNext()) {
pair = itr.next();
SysMessageID sysid = (SysMessageID) pair.getKey();
if (sysid == null) {
continue;
}
PacketReference ref = DL.get(null, sysid, false);
if (checkRefRequeued(translist, id, ref, sysid)) {
BrokerException bex = new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_MESSAGE_MAYBE_REROUTED, sysid) + ", TUID=" + id, Status.GONE);
bex.setRemote(true);
StringBuilder buf = new StringBuilder();
List interests = (List) pair.getValue();
for (int i = 0; i < interests.size(); i++) {
buf.append(String.valueOf(((ConsumerUID) interests.get(i)).longValue()));
buf.append(' ');
}
bex.setRemoteConsumerUIDs(buf.toString());
throw bex;
}
if (ref == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_MESSAGE_REF_GONE, sysid) + ", TUID=" + id, Status.CONFLICT);
}
BrokerAddress ba = ref.getBrokerAddress();
if (ba == null) {
if (!DL.isPartitionMode()) {
ba = myba;
} else {
refpid = ref.getPartitionedStore().getPartitionID();
ba = (BrokerAddress) myba.clone();
ba.setStoreSessionUID(refpid);
if (!refpid.equals(tranpid)) {
hasRemote = true;
}
}
} else if (!hasRemote) {
hasRemote = true;
}
if (hasRemote && checkOnly) {
return rets;
}
TransactionBroker tba = new TransactionBroker(ba);
bmcll = bmmap.get(tba.getBrokerAddress());
tbmcl = tbmmap.get(tba);
if (bmcll == null) {
bmcll = new ArrayList[2];
bmcll[0] = new ArrayList();
bmcll[1] = new ArrayList();
bmmap.put(tba.getBrokerAddress(), bmcll);
}
if (tbmcl == null) {
tbmcl = new ArrayList<>();
tbmmap.put(tba, tbmcl);
}
List interests = (List) mcmap.get(sysid);
for (int i = 0; i < interests.size(); i++) {
cuid = (ConsumerUID) interests.get(i);
bmcll[0].add(sysid);
bmcll[1].add(cuid);
scuid = (ConsumerUID) sToCmap.get(cuid);
ta = new TransactionAcknowledgement(sysid, cuid, scuid);
if (!scuid.shouldStore() || !ref.isPersistent()) {
ta.setShouldStore(false);
}
tbmcl.add(ta);
}
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "retrieveConsumedRemoteMessages() for broker " + tba + ": " + Arrays.toString(bmcll) + ", " + tbmcl);
}
}
if (!hasRemote) {
return null;
}
rets[0] = bmmap;
rets[1] = tbmmap;
return rets;
}
use of com.sun.messaging.jmq.jmsserver.core.PacketReference in project openmq by eclipse-ee4j.
the class TransactionHandler method redeliverUnackedNoConsumer.
/**
* @param sendMap consumerUID to PacketReferences map
* @param sToCmap consumerUID to stored ConsumerUID map
* @param redeliver whether set redeliver flag
* @param tid null if not for transaction rollback
* @param translist null if tid is null
*/
public static void redeliverUnackedNoConsumer(HashMap sendMap, HashMap sToCmap, boolean redeliver, TransactionUID tid, TransactionList translist) throws BrokerException {
Logger logger = Globals.getLogger();
Iterator sitr = sendMap.entrySet().iterator();
while (sitr.hasNext()) {
Map.Entry entry = (Map.Entry) sitr.next();
ConsumerUID intid = (ConsumerUID) entry.getKey();
ConsumerUID storedID = (ConsumerUID) sToCmap.get(intid);
SortedSet ss = (SortedSet) entry.getValue();
Iterator itr = ss.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference) itr.next();
SysMessageID sysid = ref.getSysMessageID();
if (!ref.isLocal()) {
if (tid != null && translist != null) {
translist.removeOrphanAck(tid, sysid, storedID, intid);
}
try {
ref.acquireDestroyRemoteReadLock();
try {
if (ref.isLastRemoteConsumerUID(storedID, intid)) {
if (ref.acknowledged(intid, storedID, !(intid.isNoAck() || intid.isDupsOK()), false, tid, translist, null, false)) {
try {
Destination d = ref.getDestination();
if (d != null) {
d.removeRemoteMessage(sysid, RemoveReason.ACKNOWLEDGED, ref);
} else {
if (DEBUG || DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Destination " + ref.getDestinationUID() + " not found on cleanup remote message [" + intid + "," + storedID + "," + ref + "]" + " for rollback transaction " + tid + " for inactive consumer");
}
}
} finally {
ref.postAcknowledgedRemoval();
}
}
}
} finally {
ref.clearDestroyRemoteReadLock();
}
} catch (Exception ex) {
logger.logStack((DEBUG_CLUSTER_TXN ? Logger.WARNING : Logger.DEBUG), "Unable to cleanup remote message " + "[" + intid + "," + storedID + "," + sysid + "]" + " on rollback transaction " + tid + " for inactive consumer.", ex);
}
BrokerAddress addr = null;
if (tid != null && translist != null) {
addr = translist.getAckBrokerAddress(tid, sysid, intid);
} else {
addr = ref.getBrokerAddress();
}
try {
HashMap prop = new HashMap();
if (tid != null) {
prop.put(ClusterBroadcast.RB_RELEASE_MSG_INACTIVE, tid.toString());
} else {
prop.put(ClusterBroadcast.RC_RELEASE_MSG_INACTIVE, "");
}
Globals.getClusterBroadcast().acknowledgeMessage(addr, sysid, intid, ClusterBroadcast.MSG_IGNORED, prop, false);
} catch (BrokerException e) {
Globals.getLogger().log(Logger.WARNING, "Unable to notify " + addr + " for remote message " + "[" + intid + ", " + storedID + ", " + ", " + sysid + "]" + " in " + (tid != null ? ("rollback transaction " + tid) : ("recover")) + " for inactive consumer.");
}
itr.remove();
continue;
}
}
if (storedID == null || intid == storedID) {
// non-durable subscriber, ignore
sitr.remove();
continue;
}
if (ss.isEmpty()) {
if (DEBUG) {
logger.log(Logger.INFO, "redeliverUnackedNoConsuemr: " + "empty local message set for consumer " + intid + "[storedID=" + storedID + "]");
}
continue;
}
// see if we are a queue
if (storedID == PacketReference.getQueueUID()) {
// queue message on
// queues are complex ->
PacketReference ref = (PacketReference) ss.first();
if (ref == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Internal Error: " + " null reterence");
}
continue;
}
if (!redeliver) {
ref.removeDelivered(storedID, false);
}
Destination d = ref.getDestination();
if (d == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Destination " + ref.getDestinationUID() + " not found for reference: " + ref);
}
continue;
}
// this puts it on the pending list
try {
d.forwardOrphanMessages(ss, storedID);
sitr.remove();
} catch (Exception ex) {
logger.log(Logger.INFO, "Internal Error: " + "Unable to re-queue message " + " to queue " + d, ex);
}
} else {
// durable
// ok - requeue the message on the subscription
Consumer cs = Consumer.getConsumer(storedID);
if (cs == null) {
if (DEBUG) {
logger.log(Logger.INFO, "Internal Error: " + " unknown consumer " + storedID);
}
continue;
}
if (!ss.isEmpty() && cs.routeMessages(ss, true)) {
// successful
sitr.remove();
}
}
}
if (DEBUG && sendMap.size() > 0) {
logger.log(Logger.INFO, tid + ":after all processing, " + sendMap.size() + " inactive consumers remaining");
}
}
use of com.sun.messaging.jmq.jmsserver.core.PacketReference in project openmq by eclipse-ee4j.
the class TransactionHandler method releaseRemovedConsumedForActiveConsumer.
private String releaseRemovedConsumedForActiveConsumer(Map sendMap, Map sToCmap, List updatedRefs, TransactionUID tid, TransactionList translist, boolean redeliver, boolean updateConsumed, int maxRollbacks, boolean dmqOnMaxRollbacks) {
String deadComment = null;
Iterator sitr = sendMap.entrySet().iterator();
while (sitr.hasNext()) {
Map.Entry entry = (Map.Entry) sitr.next();
ConsumerUID intid = (ConsumerUID) entry.getKey();
ConsumerUID stored = (ConsumerUID) sToCmap.get(intid);
if (stored == null) {
stored = intid;
}
SortedSet ss = (SortedSet) entry.getValue();
Consumer cs = Consumer.getConsumer(intid);
if (cs != null || updateConsumed) {
updateRefsState(stored, ss, (redeliver | updateConsumed), updatedRefs, tid);
}
if (cs == null) {
continue;
}
if (DEBUG) {
logger.log(Logger.INFO, tid + ":Releasing remote " + ss.size() + " msgs to consumer " + intid);
}
if (ss.size() > 0) {
if (dmqOnMaxRollbacks) {
PacketReference lastref = (PacketReference) ss.last();
String emsg = makeDeadIfMaxRollbacked(lastref, cs, tid, maxRollbacks);
if (emsg != null) {
if (deadComment == null) {
deadComment = emsg;
}
ss.remove(lastref);
}
}
Iterator itr = ss.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference) itr.next();
releaseRemoteForActiveConsumer(ref, intid, tid, translist);
}
}
}
return deadComment;
}
Aggregations