Search in sources :

Example 66 with ConsumerUID

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

the class ConsumerHandler method handle.

/**
 * Method to handle Consumer(add or delete) messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    boolean sessionPaused = false;
    boolean conPaused = false;
    Hashtable props = null;
    try {
        props = msg.getProperties();
    } catch (Exception ex) {
        logger.logStack(Logger.WARNING, "Unable to retrieve " + " properties from consumer message " + msg, ex);
    }
    if (props == null) {
        props = new Hashtable();
    }
    Long lsessionid = (Long) props.get("JMQSessionID");
    Session session = null;
    String err_reason = null;
    Boolean blockprop = (Boolean) props.get("JMQBlock");
    Consumer newc = null;
    assert blockprop == null || msg.getPacketType() == PacketType.DELETE_CONSUMER : msg;
    boolean blockprop_bool = (blockprop != null && blockprop.booleanValue());
    boolean isIndemp = msg.getIndempotent();
    // OK ... set up the reply packet
    Packet pkt = new Packet(con.useDirectBuffers());
    // correlation ID
    pkt.setConsumerID(msg.getConsumerID());
    Hashtable hash = new Hashtable();
    pkt.setPacketType(msg.getPacketType() + 1);
    int status = Status.OK;
    String warning = BrokerResources.W_ADD_CONSUMER_FAILED;
    ConsumerUID uid = null;
    Integer oldid = null;
    Subscription sub = null;
    try {
        DL.acquirePartitionLock(true);
        try {
            con.suspend();
            conPaused = true;
            if (msg.getPacketType() == PacketType.ADD_CONSUMER) {
                if (DEBUG) {
                    logger.log(Logger.INFO, "ConsumerHandler: " + "[Received AddConsumer message {0}]", msg.toString());
                }
                pkt.setPacketType(PacketType.ADD_CONSUMER_REPLY);
                if (lsessionid == null) {
                    if (DEBUG) {
                        logger.log(Logger.INFO, "ConsumerHandler: not Raptor consumer packet (no session id)");
                    }
                    // assign session same # as consumer
                    SessionUID sessionID = new SessionUID(con.getConnectionUID().longValue());
                    // single threaded .. we dont have to worry about
                    // someone else creating it
                    session = con.getSession(sessionID);
                    if (session == null) {
                        session = Session.createSession(sessionID, con.getConnectionUID(), null, coreLifecycle);
                        con.attachSession(session);
                    }
                } else {
                    SessionUID sessionID = new SessionUID(lsessionid.longValue());
                    session = con.getSession(sessionID);
                    if (session == null) {
                        throw new BrokerException("Internal Error: client set invalid" + " sessionUID " + sessionID + " session does not exist");
                    }
                }
                if (blockprop_bool) {
                    // turn off all processing
                    session.pause("Consumer - Block flag");
                    sessionPaused = true;
                }
                /* XXX-LKS KLUDGE FOR 2.0 compatibility */
                // for now, we just pass the consumer ID back on the old
                // packet .. I need to revisit this in the future
                // old consumer ID
                oldid = (Integer) props.get("JMQConsumerID");
                if (oldid != null) {
                    hash.put("JMQOldConsumerID", oldid);
                }
                Integer inttype = (Integer) props.get("JMQDestType");
                int type = (inttype == null ? -1 : inttype.intValue());
                if (type == -1) {
                    throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "Client is not sending DestType, " + "unable to add interest"));
                }
                boolean queue = DestType.isQueue(type);
                String destination = (String) props.get("JMQDestination");
                String selector = (String) props.get("JMQSelector");
                // JMS spec
                if (selector != null && selector.trim().length() == 0) {
                    selector = null;
                }
                boolean mqshare = false;
                // JMS2.0
                boolean jmsshare = false;
                boolean nolocal = false;
                Boolean b = (Boolean) props.get("JMQNoLocal");
                if (b != null && b.booleanValue()) {
                    nolocal = true;
                }
                b = (Boolean) props.get("JMQShare");
                if (b != null && b.booleanValue()) {
                    mqshare = true;
                }
                // JMS2.0
                b = (Boolean) props.get("JMQJMSShare");
                if (b != null && b.booleanValue()) {
                    jmsshare = true;
                }
                String durablename = (String) props.get("JMQDurableName");
                // JMS2.0
                String subscriptionName = (String) props.get("JMQSharedSubscriptionName");
                String clientid = getClientID(props, con);
                Boolean reconnect = (Boolean) props.get("JMQReconnect");
                Integer size = (Integer) props.get("JMQSize");
                if (mqshare && jmsshare) {
                    String emsg = "Client protocol error: both JMQShare and JMQJMSShare set to true";
                    Globals.getLogger().log(Logger.ERROR, emsg);
                    throw new BrokerException(emsg);
                }
                boolean shared = (mqshare || jmsshare);
                boolean durable = false;
                if (durablename != null) {
                    if (subscriptionName != null) {
                        Object[] args = { Subscription.getDSubLogString(clientid, durablename), "" + destination, subscriptionName };
                        logger.log(Logger.INFO, br.getKString(br.I_ADD_CONSUMER_IGNORE_SUBSCRIPTION_NAME, args));
                    }
                    subscriptionName = durablename;
                    durable = true;
                }
                if (DestType.isTemporary(type)) {
                    if (durable) {
                        String emsg = br.getKString(br.X_INVALID_DEST_DURA_CONSUMER, "" + destination, "" + subscriptionName);
                        logger.log(Logger.ERROR, emsg);
                        throw new BrokerException(emsg, br.X_INVALID_DEST_DURA_CONSUMER, null, Status.PRECONDITION_FAILED);
                    }
                    if (shared) {
                        String emsg = br.getKString(br.X_INVALID_DEST_SHARE_CONSUMER, "" + destination, "" + subscriptionName);
                        logger.log(Logger.ERROR, emsg);
                        throw new BrokerException(emsg, br.X_INVALID_DEST_SHARE_CONSUMER, null, Status.PRECONDITION_FAILED);
                    }
                }
                ConsumerParameters pm = new ConsumerParameters();
                pm.isqueue = queue;
                pm.destination = destination;
                pm.selector = selector;
                pm.clientid = clientid;
                pm.subscriptionName = subscriptionName;
                pm.durable = durable;
                pm.shared = shared;
                pm.jmsshare = jmsshare;
                pm.nolocal = nolocal;
                checkSubscriptionName(pm);
                checkClientID(pm);
                checkNoLocal(pm);
                if (reconnect != null && reconnect.booleanValue()) {
                    Globals.getLogger().log(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "JMQReconnect not implemented");
                }
                // see if we are a wildcard destination
                DestinationUID dest_uid = null;
                Destination d = null;
                if (DestinationUID.isWildcard(destination)) {
                    // dont create a destination
                    dest_uid = DestinationUID.getUID(destination, DestType.isQueue(type));
                } else {
                    Destination[] ds = null;
                    while (true) {
                        ds = DL.getDestination(con.getPartitionedStore(), destination, type, true, /* autocreate if possible */
                        !con.isAdminConnection());
                        // PART
                        d = ds[0];
                        if (d == null) {
                            break;
                        }
                        if (d.isAutoCreated()) {
                            warning = BrokerResources.W_ADD_AUTO_CONSUMER_FAILED;
                        }
                        try {
                            d.incrementRefCount();
                        } catch (BrokerException ex) {
                            // was destroyed in process
                            continue;
                        } catch (IllegalStateException ex) {
                            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER, ex, Status.ERROR);
                        }
                        // we got one
                        break;
                    }
                    if (d == null) {
                        // unable to autocreate destination
                        status = Status.NOT_FOUND;
                        // XXX error
                        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_DESTINATION_NOT_FOUND, destination), BrokerResources.X_DESTINATION_NOT_FOUND, null, Status.NOT_FOUND);
                    }
                    dest_uid = d.getDestinationUID();
                }
                if (jmsshare && mqshare) {
                    Object[] args = { "JMS", (!durable ? Subscription.getNDSubLongLogString(clientid, dest_uid, selector, subscriptionName, nolocal) : Subscription.getDSubLogString(clientid, subscriptionName)), "" + destination, "JMQShare" };
                    logger.log(Logger.INFO, br.getKString(br.I_ADD_SHARE_CONSUMER_IGNORE_CLIENT_FLAG, args));
                    mqshare = false;
                }
                Consumer c = null;
                try {
                    // LKS
                    Consumer[] retc = _createConsumer(dest_uid, con, session, selector, clientid, subscriptionName, durable, shared, jmsshare, nolocal, (size == null ? -1 : size.intValue()), msg.getSysMessageID().toString(), isIndemp, true);
                    c = retc[0];
                    newc = retc[1];
                    sub = (Subscription) retc[2];
                    if (c.getPrefetch() != -1 || size != null) {
                        hash.put("JMQSize", c.getPrefetch());
                    }
                } catch (SelectorFormatException ex) {
                    throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.W_SELECTOR_PARSE, "" + selector), BrokerResources.W_SELECTOR_PARSE, ex, Status.BAD_REQUEST);
                } catch (OutOfLimitsException ex) {
                    if (d != null && d.isQueue()) {
                        String[] args = { dest_uid.getName(), String.valueOf(d.getActiveConsumerCount()), String.valueOf(d.getFailoverConsumerCount()) };
                        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_S_QUEUE_ATTACH_FAILED, args), BrokerResources.X_S_QUEUE_ATTACH_FAILED, ex, Status.CONFLICT);
                    } else {
                        // durable
                        String[] args = { Subscription.getDSubLogString(clientid, durablename), dest_uid.getName(), String.valueOf(ex.getLimit()) };
                        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_S_DUR_ATTACH_FAILED, args), BrokerResources.X_S_DUR_ATTACH_FAILED, ex, Status.CONFLICT);
                    }
                } finally {
                    if (d != null) {
                        d.decrementRefCount();
                    }
                }
                // add the consumer to the session
                Integer acktype = (Integer) props.get("JMQAckMode");
                if (acktype != null) {
                    c.getConsumerUID().setAckType(acktype.intValue());
                }
                uid = c.getConsumerUID();
                if (props.get("JMQOldConsumerID") != null) {
                    Object[] args = { uid + (sub == null ? "" : "[" + sub + "]"), "" + dest_uid, props.get("JMQOldConsumerID") };
                    logger.log(Logger.INFO, br.getKString(br.I_CREATED_NEW_CONSUMER_FOR_OLD, args));
                }
            } else {
                // removing Interest
                if (DEBUG) {
                    logger.log(Logger.INFO, "ConsumerHandler: " + "[Received DestroyConsumer message {0}]", msg.toString());
                }
                warning = BrokerResources.W_DESTROY_CONSUMER_FAILED;
                pkt.setPacketType(PacketType.DELETE_CONSUMER_REPLY);
                String durableName = (String) props.get("JMQDurableName");
                String clientID = getClientID(props, con);
                Long cid = (Long) props.get("JMQConsumerID");
                uid = (cid == null ? null : new ConsumerUID(cid.longValue()));
                if (lsessionid != null) {
                    // passed on in
                    SessionUID sessionID = new SessionUID(lsessionid.longValue());
                    session = con.getSession(sessionID);
                } else {
                    session = Session.getSession(uid);
                }
                if (session == null && durableName == null && !isIndemp) {
                    if (con.getConnectionState() < Connection.STATE_CLEANED) {
                        logger.log(Logger.ERROR, br.getKString(br.E_UNEXPECTED_EXCEPTION, br.getKString(br.E_DELETE_CONSUMER_NO_SESSION, (lsessionid == null ? "" : lsessionid), uid + "") + "\n" + com.sun.messaging.jmq.io.PacketUtil.dumpPacket(msg)));
                        Session.dumpAll();
                    }
                }
                // retrieve the LastDelivered property
                Integer bodytype = (Integer) props.get("JMQBodyType");
                int btype = (bodytype == null ? 0 : bodytype.intValue());
                SysMessageID lastid = null;
                boolean lastidInTransaction = false;
                if (btype == PacketType.SYSMESSAGEID) {
                    int size = msg.getMessageBodySize();
                    if (size == 0) {
                        logger.log(Logger.INFO, "Warning, bad body in destroy consumer");
                    } else {
                        DataInputStream is = new DataInputStream(msg.getMessageBodyStream());
                        lastid = new SysMessageID();
                        lastid.readID(is);
                        Boolean val = (Boolean) props.get("JMQLastDeliveredIDInTransaction");
                        lastidInTransaction = (val != null && val.booleanValue());
                    }
                }
                if (DEBUG && lastid != null) {
                    logger.log(Logger.INFO, "ConsumerHandler: destroy consumer with lastID [" + lastid + ", " + lastidInTransaction + "]" + DL.get(con.getPartitionedStore(), lastid) + " for consumer " + uid);
                }
                Boolean rAll = (Boolean) props.get("JMQRedeliverAll");
                boolean redeliverAll = rAll != null && rAll.booleanValue();
                if (!sessionPaused && session != null) {
                    sessionPaused = true;
                    session.pause("Consumer removeconsumer");
                }
                destroyConsumer(con, session, uid, durableName, clientID, lastid, lastidInTransaction, redeliverAll, isIndemp);
            }
        } finally {
            DL.releasePartitionLock(true);
        }
    } catch (BrokerException ex) {
        status = ex.getStatusCode();
        String consumid = null;
        String destination = null;
        try {
            destination = (String) props.get("JMQDestination");
            if (destination == null && msg.getPacketType() != PacketType.ADD_CONSUMER) {
                destination = "";
            }
            if (oldid != null) {
                consumid = oldid.toString();
            } else {
                consumid = "";
            }
        } catch (Exception ex1) {
        }
        String[] args = { consumid, con.getRemoteConnectionString(), destination };
        err_reason = ex.getMessage();
        if (ex.getStatusCode() == Status.PRECONDITION_FAILED || ex.getStatusCode() == Status.CONFLICT) {
            logger.log(Logger.WARNING, warning, args, ex);
        } else if (ex.getStatusCode() == Status.BAD_REQUEST) {
            // Probably a bad selector
            logger.log(Logger.WARNING, warning, args, ex);
            if (ex.getCause() != null) {
                logger.log(Logger.INFO, ex.getCause().toString());
            }
        } else {
            if (isIndemp && msg.getPacketType() == PacketType.DELETE_CONSUMER) {
                logger.logStack(Logger.DEBUG, "Reprocessing Indempotent message for " + "{0} on destination {2} from {1}", args, ex);
                status = Status.OK;
                err_reason = null;
            } else {
                logger.logStack(Logger.WARNING, warning, args, ex);
            }
        }
    } catch (IOException ex) {
        logger.logStack(Logger.WARNING, "Unable to process " + " consumer request " + msg, ex);
        err_reason = ex.getMessage();
        assert false;
    } catch (SecurityException ex) {
        status = Status.FORBIDDEN;
        err_reason = ex.getMessage();
        String destination = null;
        String consumid = null;
        try {
            destination = (String) props.get("JMQDestination");
            if (oldid != null) {
                consumid = oldid.toString();
            }
        } catch (Exception ex1) {
        }
        logger.log(Logger.WARNING, warning, destination, consumid, ex);
    } finally {
        if (conPaused) {
            con.resume();
        }
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (err_reason != null) {
        hash.put("JMQReason", err_reason);
    }
    if (uid != null) {
        hash.put("JMQConsumerID", Long.valueOf(uid.longValue()));
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    con.sendControlMessage(pkt);
    if (sessionPaused) {
        session.resume("Consumer - session was paused");
    }
    if (sub != null) {
        sub.resume("Consumer - added to sub");
    }
    if (newc != null) {
        newc.resume("Consumer - new consumer");
    }
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) OutOfLimitsException(com.sun.messaging.jmq.util.lists.OutOfLimitsException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) OutOfLimitsException(com.sun.messaging.jmq.util.lists.OutOfLimitsException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 67 with ConsumerUID

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

the class RedeliverHandler method redeliver.

public void redeliver(ConsumerUID[] ids, SysMessageID[] sysids, IMQConnection con, TransactionUID tid, boolean redeliver) throws BrokerException, IOException {
    SysMessageID sysid = null;
    // really should only have one
    Set sessions = new HashSet();
    // but client to broker protocol doesnt specify
    HashMap cToM = new HashMap();
    HashMap noConsumerMap = new HashMap();
    HashMap storedIDToConsumerUIDMap = new HashMap();
    for (int i = 0; i < ids.length; i++) {
        ConsumerUID id = ids[i];
        id.setConnectionUID(con.getConnectionUID());
        sysid = sysids[i];
        PacketReference ref = DL.get(null, sysid, false);
        if (ref == null || ref.isInvalid()) {
            continue;
        }
        Session s = Session.getSession(id);
        Consumer c = null;
        if (s != null) {
            if (!sessions.contains(s)) {
                s.pause("redeliver");
                sessions.add(s);
            }
            c = (Consumer) s.getConsumerOnSession(id);
        }
        if (c == null) {
            // ok, make sure the consumer has really gone away
            // if not, something is really wrong
            // otherwise ...
            // consumer has gone away but session is still
            // valid ->
            c = Consumer.getConsumer(id);
            if (c != null) {
                logger.log(Logger.WARNING, "Internal Error " + " consumer with id of " + id + " is unavailable " + " on session " + s + "[conuid,sess conuid] =" + "[" + con.getConnectionUID().longValue() + "," + (s == null ? 0 : s.getConnectionUID().longValue()) + "] consumer session is : " + c.getSessionUID());
                continue;
            } else {
                if (s != null && s.isClientAck(id) && !s.isTransacted() && redeliver && tid == null) {
                    ConsumerUID storedID = s.getStoredIDForDetatchedConsumer(id);
                    if (storedID != null && !storedID.equals(id)) {
                        storedIDToConsumerUIDMap.put(id, storedID);
                        SortedSet refset = (SortedSet) noConsumerMap.get(id);
                        if (refset == null) {
                            refset = new TreeSet(new RefCompare());
                            noConsumerMap.put(id, refset);
                        }
                        ref.removeInDelivery(storedID);
                        refset.add(ref);
                    }
                }
                // the consumer for this message has been
                // closed before the redeliver was requested
                // (this means the message has not been acked and
                // the session is open)
                // we dont need to deliver this message, ignore it
                logger.log(Logger.DEBUG, " consumer with id of " + id + " is unavailable " + " on session " + s + "[conuid,sess conuid] =" + "[" + con.getConnectionUID().longValue() + "," + (s == null ? 0 : s.getConnectionUID().longValue()) + "] it has been closed");
                continue;
            }
        }
        // for client < 4.1, need check 'redeliver' as well
        if (redeliver && (tid != null || s.isTransacted())) {
            if (tid == null) {
                tid = s.getCurrentTransactionID();
            }
            TransactionList[] tls = Globals.getDestinationList().getTransactionList(con.getPartitionedStore());
            TransactionList translist = tls[0];
            if (translist != null) {
                if (checkRemovedConsumedMessage(ref, id, tid, translist, true)) {
                    if (DEBUG_CLUSTER_TXN) {
                        logger.log(logger.INFO, "Ignore redeliver request for [" + sysid + ":" + id + "], removed with transaction (rerouted)" + tid);
                    }
                    continue;
                }
                if (checkRemovedConsumedMessage(ref, id, tid, translist, false)) {
                    if (DEBUG_CLUSTER_TXN) {
                        logger.log(logger.INFO, "Ignore redeliver request for [" + sysid + ":" + id + "], removed with transaction " + tid);
                    }
                    continue;
                }
            }
        }
        Set set = (Set) cToM.get(c);
        if (set == null) {
            set = new LinkedHashSet();
            cToM.put(c, set);
        }
        if (!set.contains(ref)) {
            ref.removeInDelivery((c.getStoredConsumerUID() == null ? c.getConsumerUID() : c.getStoredConsumerUID()));
            set.add(ref);
        } else if (DEBUG_CLUSTER_TXN) {
            logger.log(logger.INFO, "Ignore duplicated redeliver request [" + sysid + ":" + id + "]");
        }
        if (redeliver) {
            ref.consumed(c.getStoredConsumerUID(), s.isDupsOK(c.getConsumerUID()), false);
        } else {
            ref.removeDelivered(c.getStoredConsumerUID(), false);
        }
    }
    Iterator itr = cToM.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        Consumer c = (Consumer) entry.getKey();
        Set msgs = (Set) entry.getValue();
        c.pause("start redeliver");
        c.routeMessages(msgs, true);
        c.resume("end redeliver");
    }
    // help gc
    cToM.clear();
    if (noConsumerMap.size() > 0) {
        try {
            logger.log(logger.DEBUG, "REDELIVER unacked for closed consumers: " + noConsumerMap);
            TransactionHandler.redeliverUnackedNoConsumer(noConsumerMap, storedIDToConsumerUIDMap, redeliver, null, null);
        } catch (Exception e) {
            logger.logStack(logger.WARNING, "Exception in redelivering unacked messages for closed consumers", e);
        }
    }
    itr = sessions.iterator();
    while (itr.hasNext()) {
        Session s = (Session) itr.next();
        s.resume("redeliver");
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 68 with ConsumerUID

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

the class RedeliverHandler method handle.

/**
 * Method to handle DELIVER messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    Hashtable props = null;
    try {
        props = msg.getProperties();
    } catch (Exception ex) {
        logger.logStack(Logger.INFO, "Unable to retrieve " + " properties from redeliver message " + msg, ex);
        props = new Hashtable();
    }
    boolean redeliver = false;
    TransactionUID tid = null;
    if (props != null) {
        Boolean bool = (Boolean) props.get("JMQSetRedelivered");
        if (bool != null) {
            redeliver = bool.booleanValue();
        }
        Object txnid = props.get("JMQTransactionID");
        if (txnid != null) {
            if (txnid instanceof Integer) {
                tid = new TransactionUID(((Integer) txnid).intValue());
            } else {
                tid = new TransactionUID(((Long) txnid).longValue());
            }
        }
        if (tid == null) {
            // for client < 4.1
            long id = msg.getTransactionID();
            if (id != 0) {
                tid = new TransactionUID(id);
            }
        }
    }
    int size = msg.getMessageBodySize();
    int ackcount = size / REDELIVER_BLOCK_SIZE;
    int mod = size % REDELIVER_BLOCK_SIZE;
    if (ackcount == 0) {
        return true;
    }
    if (mod != 0) {
        throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "Invalid Redeliver Message Size: " + size + ". Not multiple of " + REDELIVER_BLOCK_SIZE));
    }
    if (DEBUG) {
        logger.log(Logger.DEBUG, "RedeliverMessage: processing message {0} {1}", msg.toString(), con.getConnectionUID().toString());
    }
    DataInputStream is = new DataInputStream(msg.getMessageBodyStream());
    ConsumerUID[] ids = new ConsumerUID[ackcount];
    SysMessageID[] sysids = new SysMessageID[ackcount];
    try {
        for (int i = 0; i < ackcount; i++) {
            ids[i] = new ConsumerUID(is.readLong());
            sysids[i] = new SysMessageID();
            sysids[i].readID(is);
        }
        redeliver(ids, sysids, con, tid, redeliver);
    } catch (Exception ex) {
        throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "Invalid Redeliver Packet", ex), ex);
    }
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID)

Example 69 with ConsumerUID

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

the class RedeliverHandler method checkRemovedConsumedMessage.

private boolean checkRemovedConsumedMessage(PacketReference ref, ConsumerUID id, TransactionUID tid, TransactionList translist, boolean rerouted) throws BrokerException {
    SysMessageID sysid = ref.getSysMessageID();
    HashMap cmap = translist.retrieveRemovedConsumedMessages(tid, rerouted);
    if (cmap != null && cmap.size() > 0) {
        List interests = (List) cmap.get(sysid);
        if (interests == null || interests.size() == 0) {
            return false;
        }
        for (int j = 0; j < interests.size(); j++) {
            ConsumerUID intid = (ConsumerUID) interests.get(j);
            if (intid.equals(id)) {
                TransactionState ts = translist.retrieveState(tid);
                if (ts != null && ts.getState() == TransactionState.FAILED) {
                    if (!rerouted) {
                        TransactionHandler.releaseRemoteForActiveConsumer(ref, id, tid, translist);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 70 with ConsumerUID

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

the class TransactionHandler method doRemoteRollback.

private void doRemoteRollback(TransactionList translist, TransactionUID id, int nextState) throws BrokerException {
    if (nextState != TransactionState.ROLLEDBACK) {
        throw new BrokerException("Unexpected state " + nextState + " for transactionUID:" + id);
    }
    if (!translist.hasRemoteBroker(id)) {
        return;
    }
    if (Globals.getClusterBroadcast().getClusterVersion() < ClusterBroadcast.VERSION_410) {
        return;
    }
    TransactionBroker[] bas = null;
    try {
        bas = translist.getClusterTransactionBrokers(id);
        if (DEBUG_CLUSTER_TXN) {
            StringBuilder buf = new StringBuilder();
            buf.append("Rollback transaction ").append(id).append(", remote brokers");
            for (TransactionBroker ba : bas) {
                buf.append("\n\t").append(ba);
            }
            logger.log(logger.INFO, buf.toString());
        }
        BrokerAddress addr = null;
        UID tranpid = null;
        if (Globals.getDestinationList().isPartitionMode()) {
            tranpid = translist.getPartitionedStore().getPartitionID();
        }
        for (int i = 0; i < bas.length; i++) {
            if (Globals.getDestinationList().isPartitionMode()) {
                if (tranpid.equals(bas[i].getBrokerAddress().getStoreSessionUID())) {
                    continue;
                }
            } else if (bas[i].getBrokerAddress() == Globals.getMyAddress()) {
                continue;
            }
            addr = bas[i].getCurrentBrokerAddress();
            if (addr == Globals.getMyAddress()) {
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Transaction remote broker current address " + bas[i].toString() + " is my address, TUID=" + id);
                }
            } else {
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Transaction remote broker current address " + addr + ", TUID=" + id);
                }
            }
            try {
                if (addr != null) {
                    Globals.getClusterBroadcast().acknowledgeMessage2P(addr, (SysMessageID[]) null, (ConsumerUID[]) null, ClusterBroadcast.MSG_ROLLEDBACK, null, Long.valueOf(id.longValue()), tranpid, false, false);
                } else {
                    throw new BrokerDownException(br.getKString(br.X_CLUSTER_UNICAST_UNREACHABLE, bas[i]), Status.GONE);
                }
            } catch (BrokerException e) {
                String emsg = br.getKString(br.W_ROLLBACK_TXN_NOTIFY_REMOTE_BKR_FAIL, bas[i], id);
                if (e.getStatusCode() == Status.GONE || e.getStatusCode() == Status.TIMEOUT || e instanceof BrokerDownException) {
                    logger.log(logger.WARNING, emsg + ": " + e.getMessage());
                } else {
                    logger.logStack(logger.WARNING, emsg, e);
                }
            }
        }
    } catch (Exception e) {
        StringBuilder buf = new StringBuilder();
        if (bas != null) {
            for (TransactionBroker ba : bas) {
                buf.append("\n\t").append(ba);
            }
        }
        String emsg = br.getKString(br.W_ROLLBACK_TXN_NOTIFY_RMEOTE_BKRS_FAIL, buf.toString(), id);
        logger.logStack(logger.WARNING, emsg, e);
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) UID(com.sun.messaging.jmq.util.UID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) 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) BrokerDownException(com.sun.messaging.jmq.jmsserver.util.BrokerDownException)

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