Search in sources :

Example 1 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination 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 2 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination 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 3 with Destination

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

the class CompactDestinationHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Compacting: " + cmd_props);
    }
    logger.log(Logger.INFO, Globals.getBrokerResources().I_COMPACTING, cmd_props);
    String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
    Integer type = (Integer) cmd_props.get(MessageType.JMQ_DEST_TYPE);
    int status = Status.OK;
    String errMsg = null;
    boolean compactAll = false;
    HAMonitorService hamonitor = Globals.getHAMonitorService();
    if (hamonitor != null && hamonitor.inTakeover()) {
        status = Status.ERROR;
        errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
        logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
    } else {
        try {
            if (destination != null) {
                // compact one destination
                Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type.intValue()));
                // PART
                Destination d = ds[0];
                if (d != null) {
                    if (d.isPaused()) {
                        d.compact();
                    } else {
                        status = Status.ERROR;
                        String msg = rb.getString(rb.E_DESTINATION_NOT_PAUSED);
                        errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, msg);
                        logger.log(Logger.ERROR, errMsg);
                    }
                } else {
                    status = Status.ERROR;
                    String subError = rb.getString(rb.E_NO_SUCH_DESTINATION, getDestinationType(type.intValue()), destination);
                    errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, subError);
                    logger.log(Logger.ERROR, errMsg);
                }
            } else {
                Iterator[] itrs = DL.getAllDestinations(null);
                Iterator itr = itrs[0];
                boolean docompact = true;
                while (itr.hasNext()) {
                    // make sure all are paused
                    Destination d = (Destination) itr.next();
                    /*
                         * Skip internal, admin, or temp destinations. Skipping temp destinations may need to be revisited.
                         */
                    if (d.isInternal() || d.isAdmin() || d.isTemporary()) {
                        continue;
                    }
                    if (!d.isPaused()) {
                        docompact = false;
                        status = Status.ERROR;
                        String msg = rb.getString(rb.E_SOME_DESTINATIONS_NOT_PAUSED);
                        errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, msg);
                        logger.log(Logger.ERROR, errMsg);
                    }
                }
                if (docompact) {
                    itrs = DL.getAllDestinations(null);
                    // PART
                    itr = itrs[0];
                    while (itr.hasNext()) {
                        Destination d = (Destination) itr.next();
                        /*
                             * Skip internal, admin, or temp destinations. Skipping temp destinations may need to be revisited.
                             */
                        if (d.isInternal() || d.isAdmin() || d.isTemporary()) {
                            continue;
                        }
                        d.compact();
                    }
                }
            }
        } catch (Exception e) {
            status = Status.ERROR;
            if (compactAll) {
                errMsg = rb.getString(rb.X_COMPACT_DSTS_EXCEPTION, e.toString());
            } else {
                errMsg = rb.getString(rb.X_COMPACT_DST_EXCEPTION, destination, e.toString());
            }
            logger.log(Logger.ERROR, errMsg, e);
        }
    }
    // Send reply
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    setProperties(reply, MessageType.COMPACT_DESTINATION_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) Packet(com.sun.messaging.jmq.io.Packet) Iterator(java.util.Iterator) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)

Example 4 with Destination

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

the class DebugHandler method getDestinationInfo.

private Hashtable getDestinationInfo(DestinationUID uid) throws Exception {
    Destination[] ds = DL.getDestination(null, uid);
    Destination d = ds[0];
    if (d == null) {
        throw new Exception("Can not find Destination " + uid);
    }
    return d.getDebugState();
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination)

Example 5 with Destination

use of com.sun.messaging.jmq.jmsserver.core.Destination 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

Destination (com.sun.messaging.jmq.jmsserver.core.Destination)76 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)39 Iterator (java.util.Iterator)29 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)25 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)25 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)20 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)18 HashMap (java.util.HashMap)18 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)17 IOException (java.io.IOException)16 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)15 ArrayList (java.util.ArrayList)12 List (java.util.List)11 Packet (com.sun.messaging.jmq.io.Packet)9 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)9 Map (java.util.Map)9 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)8 SizeString (com.sun.messaging.jmq.util.SizeString)8 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)7 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)7