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
d= Destination.getDestination(c.getDestinationUID());
// 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();
LinkedHashSet openmsgs = new LinkedHashSet();
// OK .. get the acks .. if its a FalconRemote
// we sent the messages directly and must explicitly ack
synchronized(deliveredMessages) {
if (c != null) {
cleanupList.put(uid, c.getParentList());
}
Prioritized cparent = (Prioritized)cleanupList.get(uid);
if (DEBUG) {
logger.log(logger.INFO, "BrokerConsumers.removeConsumer:"+uid+
", pending="+pendingMsgs+", cleanup="+cleanup+", cparent="+cparent);
}
Iterator itr = deliveredMessages.values().iterator();
while (itr.hasNext()) {
ackEntry e = (ackEntry)itr.next();
if (!e.getConsumerUID().equals(uid)) continue;
if (e.getTUID() != null) continue;
if (pendingMsgs != null && !cleanup) {
if (pendingMsgs.contains(e.getSysMessageID())) {
continue;
}
}
if (DEBUG && DEBUG_CLUSTER_MSG) {
logger.log(logger.DEBUG,
"BrokerConsumers.removeConsumer:"+uid+", remove ackEntry="+e+ ", c="+c);
}
itr.remove();
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 (cparent == null) {
e.acknowledged(false);
} else {
PacketReference ref = e.getReference();
if (ref != null) openmsgs.add(ref);
}
}
if (cparent != null && openmsgs.size() > 0) {
cparent.addAllOrdered(openmsgs);
}
if (cleanup || pendingMsgs == null) {
cleanupList.remove(uid);
pendingConsumerUIDs.remove(uid);
} else {
pendingConsumerUIDs.put(uid, pendingMsgs);
}
}
if (c != null) {
c.destroyConsumer(destroySet, false, false);
if (d != null) {
d.removeConsumer(uid, false);
}
}
}