Search in sources :

Example 1 with Prioritized

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();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) Prioritized(com.sun.messaging.jmq.util.lists.Prioritized) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) LinkedHashMap(java.util.LinkedHashMap) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Iterator(java.util.Iterator) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) NoPersistPartitionedStoreImpl(com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)1 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 NoPersistPartitionedStoreImpl (com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl)1 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)1 Prioritized (com.sun.messaging.jmq.util.lists.Prioritized)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1