Search in sources :

Example 1 with Session

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

Example 2 with Session

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

the class AckHandler method handleDeadMsgs.

public void handleDeadMsgs(IMQConnection con, SysMessageID[] ids, ConsumerUID[] cids, int deadrs, Throwable thr, String comment, int deliverCnt, List cleanList) throws BrokerException {
    RemoveReason deadReason = RemoveReason.UNDELIVERABLE;
    if (deadrs == DEAD_REASON_EXPIRED) {
        deadReason = RemoveReason.EXPIRED_BY_CLIENT;
    }
    for (int i = 0; i < ids.length; i++) {
        Session s = Session.getSession(cids[i]);
        if (s == null) {
            // consumer does not have session
            // really nothing to do, ignore
            logger.log(Logger.DEBUG, "Dead message for Unknown Consumer/Session" + cids[i]);
            continue;
        }
        if (DEBUG) {
            logger.log(logger.INFO, "handleDead[" + i + ", " + ids.length + "]:sysid=" + ids[i] + ", cid=" + cids[i] + ", on connection " + con);
        }
        PacketReference ref = (PacketReference) s.handleDead(cids[i], ids[i], deadReason, thr, comment, deliverCnt);
        // no consumers .. so clean it up
        if (ref != null) {
            cleanList.add(ref);
        }
    }
}
Also used : RemoveReason(com.sun.messaging.jmq.jmsserver.util.lists.RemoveReason) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 3 with Session

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

the class AckHandler method handleAcks.

public void handleAcks(IMQConnection con, SysMessageID[] ids, ConsumerUID[] cids, boolean ackack, List cleanList) throws BrokerException, IOException {
    // we could eliminate on of the lookups
    for (int i = 0; i < ids.length; i++) {
        if (DEBUG) {
            logger.log(logger.INFO, "handleAcks[" + i + ", " + ids.length + "]:sysid=" + ids[i] + ", cid=" + cids[i] + ", on connection " + con);
        }
        Session s = Session.getSession(cids[i]);
        if (s == null) {
            // consumer does not have session
            Consumer c = Consumer.getConsumer(cids[i]);
            if (c == null) {
                if (!con.isValid() || con.isBeingDestroyed()) {
                    if (DEBUG) {
                        logger.log(logger.INFO, "Received ack for consumer " + cids[i] + " on closing connection " + con);
                    }
                    continue;
                }
                if (BrokerStateHandler.isShutdownStarted()) {
                    throw new BrokerException(br.I_ACK_FAILED_BROKER_SHUTDOWN);
                }
                throw new BrokerException(br.getKString(br.I_ACK_FAILED_NO_CONSUMER, cids[i]), Status.NOT_FOUND);
            } else if (c.getConsumerUID().getBrokerAddress() != Globals.getClusterBroadcast().getMyAddress()) {
                // remote consumer
                PacketReference ref = DL.get(null, ids[i]);
                if (ref == null) {
                    BrokerException bex = new BrokerException(br.getKString(br.I_ACK_FAILED_MESSAGE_REF_GONE, ids[i]) + "[" + cids[i] + "]", Status.GONE);
                    bex.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                    bex.setRemote(true);
                    throw bex;
                }
                ConsumerUID cuid = c.getConsumerUID();
                // but who knows if that will change
                if (ref.acknowledged(cuid, c.getStoredConsumerUID(), !cuid.isDupsOK(), true, ackack)) {
                    cleanList.add(ref);
                }
            } else {
                String emsg = br.getKString(br.I_LOCAL_CONSUMER_ACK_FAILED_NO_SESSION, "[" + ids[i] + ", " + cids[i] + "]", cids[i]);
                logger.log(Logger.WARNING, emsg);
                throw new BrokerException(emsg);
            }
        } else {
            if (fi.FAULT_INJECTION) {
                PacketReference ref = DL.get(null, ids[i]);
                if (ref != null && !ref.getDestination().isAdmin() && !ref.getDestination().isInternal()) {
                    if (fi.checkFault(fi.FAULT_ACK_MSG_1_5, null)) {
                        fi.unsetFault(fi.FAULT_ACK_MSG_1_5);
                        BrokerException bex = new BrokerException("FAULT:" + fi.FAULT_ACK_MSG_1_5, Status.GONE);
                        bex.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                        bex.setRemote(true);
                        throw bex;
                    }
                }
            }
            PacketReference ref = (PacketReference) s.ackMessage(cids[i], ids[i], ackack);
            try {
                s.postAckMessage(cids[i], ids[i], ackack);
            } finally {
                if (ref != null) {
                    cleanList.add(ref);
                }
            }
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 4 with Session

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

the class AckHandler method handleUndeliverableMsgs.

public void handleUndeliverableMsgs(IMQConnection con, SysMessageID[] ids, ConsumerUID[] cids, List cleanList, int deliverCnt, boolean deliverCntUpdateOnly) throws BrokerException {
    for (int i = 0; i < ids.length; i++) {
        Session s = Session.getSession(cids[i]);
        if (s == null) {
            // really nothing to do, ignore
            if (DEBUG) {
                logger.log(Logger.INFO, "Undeliverable message for Unknown Consumer/Session" + cids[i]);
            }
        }
        if (DEBUG) {
            logger.log(logger.INFO, "handleUndeliverable[" + i + ", " + ids.length + "]:sysid=" + ids[i] + ", cid=" + cids[i] + ", on connection " + con);
        }
        PacketReference ref = (s == null ? null : (PacketReference) s.handleUndeliverable(cids[i], ids[i], deliverCnt, deliverCntUpdateOnly));
        // no consumers .. so clean it up
        if (ref != null) {
            cleanList.add(ref);
        }
    }
}
Also used : PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 5 with Session

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

the class JMSServiceImpl method fetchMessage.

/**
 * Fetch a message from the broker.
 *
 * @param connectionId The Id of the connection
 * @param sessionId The Id of the session
 * @param consumerId The Id of the consumer for which to fetch the message
 * @param timeout The maximum time to wait (in milliseconds) for a message to be available before returning.<br>
 * Note that the method must return immediately if there is a message available for this consumerId at the time the call
 * is made.<br>
 * <UL>
 * <LI>When timeout is positive, the call must wait for a maximum of the specificied number of milliseconds before
 * returning. If a message is available before the timeout expires, the method returns with the message as soon as it is
 * available.</LI>
 * <LI>When timeout is 0, the call must block until a message is available to return or until the session is stopped.
 * </LI>
 * <LI>When the timeout is negative (less than 0), the call must return immediately, with a message if one is available
 * or with a null, if a message is not available immediately.</LI>
 * </UL>
 * @param acknowledge If this is set to {@code true} then it implies that the caller is asking for the message to be
 * <b>acknowledged</b> before the method returns. If this operation is part of a transaction, the {@code transactionId}
 * parameter will be non-zero.
 * @param transactionId If non-zero, this is the transactionId in which to acknowledge the message being returned if the
 * {@code acknowledge} parameter is set to {@code true}.
 *
 * @return The JMSPacket which contains the message being returned.
 *
 * @throws JMSServiceException if broker encounters an error. {@link JMSServiceReply.Status} contains the reason for the
 * error.
 */
@Override
public JMSPacket fetchMessage(long connectionId, long sessionId, long consumerId, long timeout, boolean acknowledge, long transactionId) throws JMSServiceException {
    JMSPacket msg = null;
    IMQConnection cxn;
    Session session;
    cxn = checkConnectionId(connectionId, "fetchMessage");
    session = checkSessionId(sessionId, "fetchMessage");
    SessionListener slistener = getListener(session.getSessionUID());
    ConsumerUID conUID;
    try {
        conUID = new ConsumerUID(consumerId);
        msg = slistener.getNextConsumerPacket(conUID, timeout);
        if ((msg != null) && acknowledge) {
            TransactionUID txnUID = null;
            if (transactionId != 0) {
                txnUID = new TransactionUID(transactionId);
            }
            SysMessageID[] ids = new SysMessageID[1];
            ids[0] = ((Packet) msg).getSysMessageID();
            ConsumerUID[] cids = new ConsumerUID[1];
            cids[0] = conUID;
            Globals.getProtocol().acknowledge(cxn, txnUID, false, AckHandler.ACKNOWLEDGE_REQUEST, null, null, 0, ids, cids);
        }
    } catch (Exception e) {
        HashMap props = new HashMap();
        String errStr = "fetchMessage: Fetch Message failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", JMSServiceReply.Status.ERROR);
        throw new JMSServiceException(errStr, e, props);
    }
    return (msg);
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) JMSPacket(com.sun.messaging.jmq.io.JMSPacket) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Aggregations

Session (com.sun.messaging.jmq.jmsserver.core.Session)28 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)11 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)10 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)8 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)7 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)7 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)7 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)6 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)5 Iterator (java.util.Iterator)4 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)3 ConsumerSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.ConsumerSpi)3 AccessControlException (java.security.AccessControlException)3 Packet (com.sun.messaging.jmq.io.Packet)2 ReadWritePacket (com.sun.messaging.jmq.io.ReadWritePacket)2 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)2 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)2 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)2 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)2 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)2