use of com.sun.messaging.jmq.util.lists.Prioritized in project openmq by eclipse-ee4j.
the class BrokerConsumers method removeConsumer.
public void removeConsumer(com.sun.messaging.jmq.jmsserver.core.ConsumerUID uid, Map<TransactionUID, LinkedHashMap<SysMessageID, Integer>> pendingMsgs, boolean cleanup) throws BrokerException {
if (getDEBUG()) {
logger.log(logger.INFO, "BrokerConsumers.removeConsumer(" + uid + ", " + pendingMsgs + ", " + cleanup + ")");
}
Consumer c = null;
synchronized (removeConsumerLock) {
c = (Consumer) consumers.remove(uid);
}
if (c == null && !cleanup) {
return;
}
Destination d = null;
if (c != null) {
c.pause("MultiBroker - removing consumer");
// remove it from the destination
Destination[] ds = DL.getDestination(null, c.getDestinationUID());
// PART
d = ds[0];
// quit listening for busy events
Object listener = listeners.remove(uid);
if (listener != null) {
c.removeEventListener(listener);
}
// remove it from the active list
activeConsumers.remove(c);
}
Set destroySet = new LinkedHashSet();
LinkedHashSet openacks = new LinkedHashSet();
Map<PartitionedStore, LinkedHashSet> openmsgmp = new LinkedHashMap<>();
Map<TransactionUID, Set<AckEntry>> mypending = new LinkedHashMap<>();
boolean haspendingtxn = false;
// we sent the messages directly and must explicitly ack
synchronized (deliveredMessages) {
if (c != null) {
cleanupList.put(uid, c.getParentList());
}
Map cparentmp = (Map) cleanupList.get(uid);
if (getDEBUG()) {
logger.log(logger.INFO, "BrokerConsumers.removeConsumer:" + uid + ", pending=" + pendingMsgs + ", cleanup=" + cleanup + ", cparentmp=" + cparentmp);
}
Iterator itr = deliveredMessages.values().iterator();
while (itr.hasNext()) {
AckEntry e = (AckEntry) itr.next();
if (!e.getConsumerUID().equals(uid)) {
continue;
}
if (pendingMsgs != null) {
Iterator<Map.Entry<TransactionUID, LinkedHashMap<SysMessageID, Integer>>> itr1 = pendingMsgs.entrySet().iterator();
Map.Entry<TransactionUID, LinkedHashMap<SysMessageID, Integer>> pair = null;
TransactionUID tid = null;
LinkedHashMap<SysMessageID, Integer> sysiddcts = null;
Set<AckEntry> ackentries = null;
boolean found = false;
Integer deliverCnt = null;
while (itr1.hasNext()) {
pair = itr1.next();
tid = pair.getKey();
sysiddcts = pair.getValue();
deliverCnt = sysiddcts.get(e.getSysMessageID());
if (deliverCnt != null) {
if (tid != null && tid.longValue() == 0L) {
updateConsumed(e, deliverCnt, false);
continue;
}
if (cleanup || e.getTUID() != null) {
updateConsumed(e, deliverCnt, false);
break;
}
found = true;
ackentries = mypending.get(tid);
if (ackentries == null) {
ackentries = new LinkedHashSet();
mypending.put(tid, ackentries);
}
if (tid != null && !haspendingtxn) {
haspendingtxn = true;
}
ackentries.add(e);
updateConsumed(e, deliverCnt, false);
break;
}
}
if (found) {
continue;
}
}
if (e.getTUID() != null) {
continue;
}
if (getDEBUG()) {
logger.log(logger.DEBUG, "BrokerConsumers.removeConsumer:" + uid + ", remove AckEntry=" + e + ", c=" + c);
}
itr.remove();
if (cleanup) {
updateConsumed(e, Integer.valueOf(1), true);
}
if (c != null) {
if (c.isFalconRemote()) {
e.acknowledged(false);
} else {
PacketReference ref = e.getReference();
if (ref != null) {
ref.removeInDelivery(e.getStoredConsumerUID());
destroySet.add(ref);
}
}
continue;
}
PacketReference ref = e.getReference();
if (ref != null) {
ref.removeInDelivery(e.getStoredConsumerUID());
}
openacks.add(e);
}
itr = openacks.iterator();
while (itr.hasNext()) {
AckEntry e = (AckEntry) itr.next();
if (cparentmp == null || cparentmp.size() == 0) {
e.acknowledged(false);
} else {
PacketReference ref = e.getReference();
if (ref != null) {
PartitionedStore ps = null;
if (!ref.getDestinationUID().isQueue()) {
ps = new NoPersistPartitionedStoreImpl(e.getStoredConsumerUID());
} else {
ps = ref.getPartitionedStore();
}
LinkedHashSet set = openmsgmp.get(ps);
if (set == null) {
set = new LinkedHashSet();
openmsgmp.put(ps, set);
}
set.add(ref);
}
}
}
if (cparentmp != null && cparentmp.size() > 0 && openmsgmp.size() > 0) {
itr = openmsgmp.entrySet().iterator();
PartitionedStore ps = null;
Prioritized pl = null;
Map.Entry pair = null;
while (itr.hasNext()) {
pair = (Map.Entry) itr.next();
ps = (PartitionedStore) pair.getKey();
pl = (Prioritized) cparentmp.get(ps);
if (pl != null) {
pl.addAllOrdered((Set) pair.getValue());
} else {
logger.log(logger.WARNING, "Message(s) " + cparentmp.get(ps) + "[" + ps + "] parentlist not found on removing consumer " + uid);
}
}
}
if (cleanup || pendingMsgs == null) {
cleanupList.remove(uid);
pendingConsumerUIDs.remove(uid);
} else if (mypending.size() > 0) {
pendingConsumerUIDs.put(uid, mypending);
}
}
if (c != null) {
c.destroyConsumer(destroySet, false, false);
if (d != null) {
d.removeConsumer(uid, false);
}
}
List<Set<AckEntry>> l = null;
synchronized (pendingConsumerUIDs) {
l = new ArrayList<>(mypending.values());
}
Set<AckEntry> entries = null;
Iterator<Set<AckEntry>> itr = l.iterator();
while (itr.hasNext()) {
entries = itr.next();
AckEntry entry = null;
Iterator<AckEntry> itr1 = entries.iterator();
while (itr1.hasNext()) {
entry = itr1.next();
entry.pendingStarted();
}
}
if (haspendingtxn) {
notifyPendingCheckTimer();
}
}
Aggregations