Search in sources :

Example 6 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class TransactionHandler method redeliverUnacked.

/**
 * this method triggers a redeliver of all unacked messages in the transaction. Since there may be multiple connections
 * for the various consumers .. we guarentee that the messages for this transaction are resent in order but make no
 * guarentee about other messages arriving before these messages.
 */
public void redeliverUnacked(TransactionList translist, TransactionUID tid, boolean processActiveConsumers, boolean redeliver, boolean updateConsumed, int maxRollbacks, boolean dmqOnMaxRollbacks) throws BrokerException {
    HashMap cmap = null;
    HashMap sToCmap = null;
    cmap = translist.retrieveConsumedMessages(tid, true);
    sToCmap = translist.retrieveStoredConsumerUIDs(tid);
    if (DEBUG) {
        logger.log(logger.INFO, "redeliverUnacked:tid=" + tid + ", consumed#=" + cmap);
    }
    HashMap sendMap = sortPreprocessRetrievedMessages(cmap, sToCmap, processActiveConsumers, maxRollbacks, dmqOnMaxRollbacks, tid);
    if (DEBUG) {
        logger.log(logger.INFO, "redeliverUnacked:tid=" + tid + ", sendMap#=" + sendMap.size());
    }
    HashMap sendMapRemoved = null;
    if (processActiveConsumers) {
        HashMap cmapRemoved = translist.retrieveRemovedConsumedMessages(tid, false);
        sendMapRemoved = sortPreprocessRetrievedMessages(cmapRemoved, sToCmap, processActiveConsumers, maxRollbacks, dmqOnMaxRollbacks, tid);
    }
    String deadComment = null;
    // OK -> now we have a NEW hashmap id -> messages (sorted)
    // lets resend the ones we can to the consumer
    ArrayList updatedRefs = new ArrayList();
    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 && processActiveConsumers) || updateConsumed) {
            updateRefsState(stored, ss, (redeliver | updateConsumed), updatedRefs, tid);
        }
        if (cs == null) {
            if (DEBUG) {
                logger.log(Logger.INFO, tid + ":Can not redeliver messages to " + intid + " consumer is gone");
            }
            continue;
        }
        if (DEBUG) {
            logger.log(Logger.INFO, tid + ":Redelivering " + ss.size() + " msgs to " + intid);
        }
        if (!processActiveConsumers) {
            // we dont want to process open consumers
            // if the boolen is false ->
            // remove them so that we only process inactive
            // consumers later
            sitr.remove();
        } else 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);
                }
            }
            if (cs.routeMessages(ss, true)) {
                if (DEBUG) {
                    logger.log(Logger.INFO, "Sucessfully routed msgs to " + cs);
                }
                sitr.remove();
            } else {
                // couldnt route messages ..invalid consumer
                if (DEBUG) {
                    logger.log(Logger.INFO, "Could not route messages to " + cs);
                }
            }
        }
    }
    // ones that dont have consumers)
    if (DEBUG) {
        logger.log(Logger.INFO, tid + ":after redeliver, " + sendMap.size() + " inactive consumers remaining");
    }
    // loop through remaining messages
    redeliverUnackedNoConsumer(sendMap, sToCmap, redeliver, tid, translist);
    if (sendMapRemoved != null) {
        releaseRemovedConsumedForActiveConsumer(sendMapRemoved, sToCmap, updatedRefs, tid, translist, redeliver, updateConsumed, maxRollbacks, dmqOnMaxRollbacks);
    }
    if (deadComment != null) {
        throw new MaxConsecutiveRollbackException(deadComment);
    }
}
Also used : Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) MaxConsecutiveRollbackException(com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException) Map(java.util.Map) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) SortedSet(java.util.SortedSet)

Example 7 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID 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");
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) Logger(com.sun.messaging.jmq.util.log.Logger) SortedSet(java.util.SortedSet) BrokerDownException(com.sun.messaging.jmq.jmsserver.util.BrokerDownException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) IOException(java.io.IOException) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) MaxConsecutiveRollbackException(com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Iterator(java.util.Iterator) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) Map(java.util.Map) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap)

Example 8 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class TransactionHandler method calculateStoredRouting.

private boolean calculateStoredRouting(PartitionedStore pstore, TransactionWorkMessage twm) throws BrokerException {
    PacketReference ref = twm.getPacketReference();
    Destination[] ds = DL.getDestination(pstore, twm.getDestUID());
    Destination dest = ds[0];
    ConsumerUID[] storedInterests = null;
    if (dest == null) {
        String msg = "Could not find destination for " + twm.getDestUID() + " refDest= " + ref.getDestinationName();
        logger.log(Logger.ERROR, msg);
        throw new BrokerException(msg);
    }
    try {
        storedInterests = dest.calculateStoredInterests(ref);
        twm.setStoredInterests(storedInterests);
    } catch (SelectorFormatException sfe) {
        throw new BrokerException("Could not route transacted message on commit", sfe);
    }
    if (storedInterests == null) {
        if (DEBUG_CLUSTER_TXN) {
            logger.log(Logger.INFO, Thread.currentThread().getName() + " stored routing = null " + twm + " persist=" + ref.isPersistent());
        }
        return false;
    } else {
        if (DEBUG_CLUSTER_TXN) {
            for (int i = 0; i < storedInterests.length; i++) {
                logger.log(Logger.INFO, Thread.currentThread().getName() + " stored routing " + storedInterests[i] + " " + twm);
            }
        }
    }
    return true;
}
Also used : SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference)

Example 9 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class DebugHandler method getDebugInfo.

public Hashtable getDebugInfo(String arg, String target, String targetType, Properties p) throws Exception {
    if (arg.equals("cxn")) {
        if (target == null) {
            return getAllCxnInfo(null);
        } else {
            ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
            return getCxnInfo(uid);
        }
    } else if (arg.equals("config")) {
        return getConfig();
    } else if (arg.equals("memory")) {
        return getMemory();
    } else if (arg.equals("dst")) {
        if (target == null) {
            return DL.getAllDebugState();
        } else {
            boolean isQueue = false;
            if (targetType == null) {
                throw new Exception("topic or queue not " + "specified with -t [t|q]");
            } else if (targetType.equals("t")) {
                isQueue = false;
            } else if (targetType.equals("q")) {
                isQueue = true;
            } else {
                throw new Exception("Unknown -t argument " + targetType + " expected t or q");
            }
            DestinationUID uid = DestinationUID.getUID(target, isQueue);
            return getDestinationInfo(uid);
        }
    } else if (arg.equals("ses")) {
        if (target == null) {
            return Session.getAllDebugState();
        } else {
            SessionUID uid = new SessionUID(Long.parseLong(target));
            return getSession(uid);
        }
    } else if (arg.equals("prd")) {
        if (target == null) {
            return Producer.getAllDebugState();
        } else {
            ProducerUID uid = new ProducerUID(Long.parseLong(target));
            return getProducerInfo(uid);
        }
    } else if (arg.equals("con")) {
        if (target == null) {
            return Consumer.getAllDebugState();
        } else {
            ConsumerUID uid = new ConsumerUID(Long.parseLong(target));
            return getConInfo(uid);
        }
    } else if (arg.equals("svc")) {
        if (target == null) {
            logger.log(Logger.INFO, "XXX - target of null " + "not implemented for " + arg);
        } else {
            return getSvcInfo(target);
        }
    } else if (arg.equals("db")) {
        return getDBInfo();
    } else if (arg.equals("trans")) {
        if (target == null) {
            return getTransactionInfo(null);
        } else {
            TransactionUID uid = new TransactionUID(Long.parseLong(target));
            return getTransactionInfo(uid);
        }
    } else if (arg.equals("pool")) {
        if (target == null) {
            logger.log(Logger.INFO, "XXX - target of null " + "not implemented for " + arg);
        } else {
            return getThreadPoolInfo(target);
        }
    } else if (arg.equals("threads")) {
        return SupportUtil.getAllStackTracesAsMap();
    } else if (arg.equals("cls")) {
        return getClusterInfo();
    } else if (arg.equals("bkr")) {
        return getBrokerInfo();
    } else if (arg.equals("pkt")) {
        String full = p.getProperty("full");
        boolean fullDump = false;
        if (full != null && full.equalsIgnoreCase("True")) {
            fullDump = true;
        }
        return getPktInfo(target, targetType, fullDump);
    }
    logger.log(Logger.INFO, "Unknown dump arg " + arg);
    return null;
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID)

Example 10 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class DebugHandler method getPktInfo.

private Hashtable getPktInfo(String target, String type, boolean full) throws Exception {
    Hashtable ht = new Hashtable();
    if (type == null || type.length() == 0 || type.equals("bkr")) {
        Hashtable dest = new Hashtable();
        Iterator[] itrs = DL.getAllDestinations(null);
        Iterator itr = itrs[0];
        while (itr.hasNext()) {
            Destination d = (Destination) itr.next();
            dest.put(d.getDestinationUID().toString(), d.getDebugMessages(full));
        }
        ht.put("Destinations", dest);
    // XXX LKS 1/8/2004
    // add entries for sessions, etc
    // 
    } else if (type.equals("q") || type.equals("t")) {
        boolean isQueue = false;
        if (type.equals("t")) {
            isQueue = false;
        } else if (type.equals("q")) {
            isQueue = true;
        }
        DestinationUID uid = DestinationUID.getUID(target, isQueue);
        Destination[] ds = DL.getDestination(null, uid);
        Destination d = ds[0];
        if (d == null) {
            throw new Exception("Unknown destination " + uid);
        } else {
            ht.putAll(d.getDebugMessages(full));
        }
    } else if (type.equals("con")) {
        if (target == null) {
            throw new Exception("Please specify consumerUID");
        } else {
            ConsumerUID uid = new ConsumerUID(Long.parseLong(target));
            Consumer c = Consumer.getConsumer(uid);
            if (c == null) {
                throw new Exception("Unknown consumer " + uid);
            } else {
                ht.put(uid.toString(), c.getDebugMessages(full));
            }
        }
    } else if (type.equals("cxn")) {
        if (target == null) {
            throw new Exception("Please specify connectionUID");
        }
        ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
        IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
        if (cxn == null) {
            throw new Exception("Can not find connection " + uid);
        }
        ht.put(target, cxn.getDebugMessages(full));
    } else if (type.equals("ses")) {
        ht.put("Dump acks ", target);
        if (target == null) {
            throw new Exception("Please specify SessionUID");
        }
        SessionUID uid = new SessionUID(Long.parseLong(target));
        Session sess = Session.getSession(uid);
        if (sess == null) {
            throw new Exception("Can not find session " + uid);
        }
        ht.put(target, sess.getDebugMessages(full));
    } else {
        ht.put("Error", "Unknown pkt type " + type);
    }
    return ht;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Aggregations

ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)83 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)29 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)28 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)27 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)22 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)21 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)21 Iterator (java.util.Iterator)21 HashMap (java.util.HashMap)19 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)17 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 List (java.util.List)13 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)10 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)10 Session (com.sun.messaging.jmq.jmsserver.core.Session)10 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)10 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)9