Search in sources :

Example 1 with SelectorFormatException

use of com.sun.messaging.jmq.util.selector.SelectorFormatException 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 2 with SelectorFormatException

use of com.sun.messaging.jmq.util.selector.SelectorFormatException in project openmq by eclipse-ee4j.

the class ConsumerHandler method _createConsumer.

private Consumer[] _createConsumer(DestinationUID dest_uid, IMQConnection con, Session session, String selectorstr, String clientid, String subscriptionName, boolean durable, boolean shared, boolean jmsshare, boolean nolocal, int size, String consumerString, boolean isIndemp, boolean useFlowControl) throws BrokerException, SelectorFormatException, IOException {
    Consumer c = null;
    Consumer newc = null;
    Subscription sub = null;
    String selector = selectorstr;
    if (selectorstr != null && selectorstr.trim().length() == 0) {
        selector = null;
    }
    try {
        int prefetch = -1;
        if (isIndemp) {
            // see if we already created it
            c = Consumer.getConsumer(consumerString);
            if (c != null) {
                prefetch = c.getPrefetch();
            }
        }
        if (c == null) {
            c = new Consumer(dest_uid, selector, nolocal, con.getConnectionUID());
            c.setCreator(consumerString);
            newc = c;
            newc.pause("Consumer: new consumer");
            // OK, determine if we are a wildcard or not
            Destination[] ds = DL.getDestination(con.getPartitionedStore(), dest_uid);
            // PART
            Destination d = ds[0];
            boolean wildcard = dest_uid.isWildcard();
            // NOTE: if d == null, wildcard == true
            int cprefetch = size;
            int dprefetch = (wildcard ? -1 : (!shared ? d.getMaxPrefetch() : d.getSharedConsumerFlowLimit()));
            prefetch = (dprefetch == -1) ? cprefetch : (cprefetch == -1 ? cprefetch : (cprefetch > dprefetch ? dprefetch : cprefetch));
            c.setPrefetch(prefetch, useFlowControl);
            // actual subscription added to the destination
            if (subscriptionName != null && durable) {
                if (!shared) {
                    logger.log(Logger.INFO, br.getKString(br.I_CREATE_UNSHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName), dest_uid));
                } else {
                    logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName) + (jmsshare ? "jms" : "mq"), dest_uid));
                }
                // durable
                // get the subscription ... this may throw
                // an exception IF we cant
                sub = Subscription.findCreateDurableSubscription(clientid, subscriptionName, shared, jmsshare, dest_uid, selector, nolocal, true);
                sub.setCreator(consumerString);
                sub.pause("Consumer attaching to durable");
                // add the consumer .. this may throw an
                // exception IF
                sub.attachConsumer(c, con);
                c.localConsumerCreationReady();
                Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
                LinkedHashSet dset = null;
                Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
                boolean notify = true;
                while (itr.hasNext()) {
                    dset = itr.next();
                    if (dset == null) {
                        continue;
                    }
                    Iterator<Destination> itr1 = dset.iterator();
                    while (itr1.hasNext()) {
                        Destination dd = itr1.next();
                        if (dd == null) {
                            continue;
                        }
                        Subscription oldsub = null;
                        try {
                            oldsub = (Subscription) dd.addConsumer(sub, notify, con);
                        } catch (ConsumerAlreadyAddedException e) {
                            logger.log(logger.INFO, e.getMessage());
                        }
                        if (oldsub != null) {
                            oldsub.purge();
                        }
                    }
                    notify = false;
                }
                sub.sendCreateSubscriptionNotification(c);
            } else if ((wildcard || !d.isQueue()) && shared) {
                logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_NONDURA_SUB, Subscription.getNDSubLongLogString(clientid, dest_uid, selectorstr, subscriptionName, nolocal), "" + dest_uid));
                sub = Subscription.createAttachNonDurableSub(c, con, subscriptionName, shared, jmsshare);
                c.localConsumerCreationReady();
                if (sub != null) {
                    sub.pause("Consumer: attaching to nondurable");
                    Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
                    LinkedHashSet dset = null;
                    Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
                    while (itr.hasNext()) {
                        dset = itr.next();
                        if (dset == null) {
                            continue;
                        }
                        Iterator<Destination> itr1 = dset.iterator();
                        while (itr1.hasNext()) {
                            Destination dd = itr1.next();
                            if (dd != null) {
                                dd.addConsumer(sub, true, con);
                            }
                        }
                    }
                }
                c.attachToConnection(con.getConnectionUID());
                if (sub != null) {
                    sub.sendCreateSubscriptionNotification(c);
                }
            } else {
                c.localConsumerCreationReady();
                // non-durable
                Destination dd = null;
                Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
                LinkedHashSet dset = null;
                Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
                while (itr.hasNext()) {
                    dset = itr.next();
                    if (dset == null) {
                        continue;
                    }
                    Iterator<Destination> itr1 = dset.iterator();
                    while (itr1.hasNext()) {
                        dd = itr1.next();
                        if (dd != null) {
                            dd.addConsumer(c, true, con);
                        }
                    }
                }
                c.attachToConnection(con.getConnectionUID());
                c.sendCreateConsumerNotification();
            }
        }
        if (fi.FAULT_INJECTION) {
            // e.g. imqcmd debug fault -n consumer.add.1 -o selector="mqDestinationName = 'T:t0.*'" -debug
            HashMap fips = new HashMap();
            fips.put(FaultInjection.DST_NAME_PROP, DestinationUID.getUniqueString(dest_uid.getName(), dest_uid.isQueue()));
            fi.checkFaultAndSleep(FaultInjection.FAULT_CONSUMER_ADD_1, fips);
        }
        session.attachConsumer(c);
        if (DEBUG) {
            logger.log(logger.INFO, "Attached consumer " + c + "[prefetch=" + c.getPrefetch() + ", useConsumerFlowControl=" + useFlowControl + "] to session " + session);
        }
        Consumer[] retc = new Consumer[3];
        retc[0] = c;
        retc[1] = newc;
        retc[2] = sub;
        return retc;
    } catch (Exception e) {
        Object[] args = { (durable ? Subscription.getDSubLogString(clientid, subscriptionName) : (shared ? Subscription.getNDSubLongLogString(clientid, dest_uid, selector, subscriptionName, nolocal) : "")), con, dest_uid };
        String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_ADD_AUTO_CONSUMER_FAILED, args);
        logger.logStack(logger.ERROR, emsg, e);
        try {
            if (c != null) {
                try {
                    session.detatchConsumer(c.getConsumerUID(), null, false, false, false);
                } catch (Exception e1) {
                    try {
                        c.destroyConsumer((new HashSet()), null, true, false, true);
                    } catch (Exception e2) {
                    }
                }
            }
            Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
            LinkedHashSet dset = null;
            Destination dd = null;
            Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
            while (itr.hasNext()) {
                dset = itr.next();
                if (dset == null) {
                    continue;
                }
                Iterator<Destination> itr1 = dset.iterator();
                while (itr1.hasNext()) {
                    dd = itr1.next();
                    if (dd == null) {
                        continue;
                    }
                    try {
                        if (c != null) {
                            dd.removeConsumer(c.getConsumerUID(), true);
                        }
                        if (sub != null) {
                            dd.removeConsumer(sub.getConsumerUID(), true);
                        }
                    } catch (Exception e1) {
                    }
                }
            }
            try {
                if (sub != null && c != null) {
                    sub.releaseConsumer(c.getConsumerUID());
                }
            } catch (Exception e1) {
            }
            if (subscriptionName != null && durable) {
                if (sub != null && sub.getCreator() != null && sub.getCreator().equals(consumerString)) {
                    try {
                        Subscription.unsubscribe(subscriptionName, clientid);
                    } catch (Exception e1) {
                    }
                }
            }
        } catch (Exception e3) {
        }
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        }
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        if (e instanceof SelectorFormatException) {
            throw (SelectorFormatException) e;
        }
        throw new BrokerException(emsg, e);
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) 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) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 3 with SelectorFormatException

use of com.sun.messaging.jmq.util.selector.SelectorFormatException in project openmq by eclipse-ee4j.

the class JMSServiceImpl method addConsumer.

/**
 * Add a consumer.
 * <p>
 * The initial state of the consumer must be the <u>sync</u> state.
 *
 * @param connectionId The Id of the connection in which to add the consumer
 * @param sessionId The Id of the session in which to add the consumer. The acknowledgement mode of the consumer will be
 * that of the session
 * @param dest The Destination from which the consumer will receive messages
 * @param selector The selector which will be used to filter messages
 * @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
 * @param durable if dest is Topic, if true, this is a durable subscription
 * @param share if dest is Topic, if true, this is a shared subscription
 * @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
 * true, this is a MQ Shared Subscription
 *
 * @param clientId The clientId to use when this is a durable subscription with a non-null durableName. This clientId
 * must match the one that has been set on the connection previously.
 * @param noLocal If {@code true}, consumer does not wnat to receive messages produced on the same connection<br>
 * If {@code false}, consumer wants to receive messages produced on the same connection as well.
 *
 * @return The JMSServiceReply of the request to add a consumer
 *
 * @throws JMSServiceException if the Status returned for the addConsumer method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSService#setConsumerAsync
 *
 * @see JMSServiceReply.Status#getJMQConsumerID
 *
 * @see JMSServiceReply.Status#FORBIDDEN
 * @see JMSServiceReply.Status#BAD_REQUEST
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#NOT_ALLOWED
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#CONFLICT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply addConsumer(long connectionId, long sessionId, Destination dest, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, String clientId, boolean noLocal) throws JMSServiceException {
    JMSServiceReply reply;
    IMQConnection cxn;
    HashMap props = new HashMap();
    com.sun.messaging.jmq.jmsserver.core.Destination d;
    Session session;
    com.sun.messaging.jmq.jmsserver.core.Consumer con;
    int size = 1000;
    long consumerID = 0;
    cxn = checkConnectionId(connectionId, "addConsumer");
    session = checkSessionId(sessionId, "addConsumer");
    try {
        com.sun.messaging.jmq.jmsserver.core.Destination[] ds = Globals.getDestinationList().getDestination(cxn.getPartitionedStore(), dest.getName(), (dest.getType() == Destination.Type.QUEUE));
        d = ds[0];
        /*
             * size (prefetch size) is not needed here since the broker is going to call the client method with the messages, not
             * simply dump packets till a particular size is reached.
             */
        boolean useFlowControl = false;
        con = protocol.createConsumer(d, cxn, session, selector, clientId, subscriptionName, durable, share, jmsshare, noLocal, size, new Object().toString(), cxn.getAccessController().isAccessControlEnabled(), useFlowControl);
        consumerID = con.getConsumerUID().longValue();
    } catch (Exception e) {
        String errStr = "addConsumer: Add consumer failed. Connection ID: " + connectionId + ", session ID: " + sessionId;
        logger.logStack(Logger.ERROR, errStr, e);
        if (e instanceof SelectorFormatException) {
            props.put("JMQStatus", JMSServiceReply.Status.BAD_REQUEST);
        } else {
            props.put("JMQStatus", getErrorReplyStatus(e));
        }
        if (e instanceof BrokerException) {
            String ecode = ((BrokerException) e).getErrorCode();
            if (ecode != null) {
                props.put(JMSPacketProperties.JMQErrorCode, ecode);
            }
        }
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQConsumerID", consumerID);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 4 with SelectorFormatException

use of com.sun.messaging.jmq.util.selector.SelectorFormatException in project openmq by eclipse-ee4j.

the class JMSServiceImpl method browseMessages.

@Override
public JMSPacket[] browseMessages(long connectionId, long sessionId, long consumerId) throws JMSServiceException {
    IMQConnection cxn;
    HashMap props = new HashMap();
    ConsumerUID uid;
    // Session session;
    JMSPacket[] msgs = null;
    cxn = checkConnectionId(connectionId, "browseMessages");
    // session = checkSessionId(sessionId, "browseMessages");
    checkSessionId(sessionId, "browseMessages");
    uid = new ConsumerUID(consumerId);
    if (queueBrowseList.containsKey(uid)) {
        QueueBrowserInfo qbi = (QueueBrowserInfo) queueBrowseList.get(uid);
        try {
            Destination dest = qbi.dest;
            String selector = qbi.selector;
            com.sun.messaging.jmq.jmsserver.core.Destination[] ds = null;
            com.sun.messaging.jmq.jmsserver.core.Destination d = null;
            ds = Globals.getDestinationList().getDestination(cxn.getPartitionedStore(), dest.getName(), (dest.getType() == Destination.Type.QUEUE));
            d = ds[0];
            if (d == null) {
                String errStr = "browseMessages: destination not found. Connection ID:" + connectionId + ", Session ID: " + sessionId + ", Consumer ID: " + consumerId + "destination: " + dest.toString();
                logger.log(Logger.ERROR, errStr);
                props.put("JMQStatus", JMSServiceReply.Status.NOT_FOUND);
                throw new JMSServiceException(errStr, props);
            }
            ArrayList msgIds = protocol.browseQueue(d, selector, cxn, cxn.getAccessController().isAccessControlEnabled());
            if (msgIds != null) {
                int numMsgs = msgIds.size();
                if (numMsgs == 0) {
                    return (null);
                }
                msgs = new JMSPacket[numMsgs];
                for (int i = 0; i < numMsgs; ++i) {
                    PacketReference pr = DestinationList.get(null, (SysMessageID) msgIds.get(i));
                    msgs[i] = pr.getPacket();
                }
            }
        } catch (Exception e) {
            String errStr = "browseMessages: Browse queue failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", consumer ID: " + consumerId;
            logger.logStack(Logger.ERROR, errStr, e);
            if (e instanceof SelectorFormatException) {
                props.put("JMQStatus", JMSServiceReply.Status.BAD_REQUEST);
            } else {
                props.put("JMQStatus", getErrorReplyStatus(e));
            }
            if (e instanceof BrokerException) {
                String ecode = ((BrokerException) e).getErrorCode();
                if (ecode != null) {
                    props.put(JMSPacketProperties.JMQErrorCode, ecode);
                }
            }
            throw new JMSServiceException(errStr, e, props);
        }
    } else {
        String errStr = "browseMessages: consumer ID not found. Connection ID:" + connectionId + ", Session ID: " + sessionId + ", Consumer ID: " + consumerId;
        logger.log(Logger.ERROR, errStr);
        props.put("JMQStatus", JMSServiceReply.Status.NOT_FOUND);
        throw new JMSServiceException(errStr, props);
    }
    return (msgs);
}
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) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference)

Example 5 with SelectorFormatException

use of com.sun.messaging.jmq.util.selector.SelectorFormatException in project openmq by eclipse-ee4j.

the class JMSServiceImpl method addBrowser.

@Override
public JMSServiceReply addBrowser(long connectionId, long sessionId, Destination dest, String selector) throws JMSServiceException {
    JMSServiceReply reply;
    // IMQConnection cxn;
    HashMap props = new HashMap();
    ConsumerUID uid;
    // Session session;
    // cxn = checkConnectionId(connectionId, "addBrowser");
    checkConnectionId(connectionId, "addBrowser");
    // session = checkSessionId(sessionId, "addBrowser");
    checkSessionId(sessionId, "addBrowser");
    try {
        Selector.compile(selector);
    } catch (SelectorFormatException sfe) {
        String errStr = "addBrowser: Add browser failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", destination: " + dest + ", selector: " + selector;
        logger.logStack(Logger.ERROR, errStr, sfe);
        props.put("JMQStatus", JMSServiceReply.Status.BAD_REQUEST);
        throw new JMSServiceException(errStr, sfe, props);
    }
    uid = new ConsumerUID();
    queueBrowseList.put(uid, new QueueBrowserInfo(dest, selector));
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQConsumerID", uid.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Aggregations

SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)14 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)10 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)7 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)6 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)5 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)5 Subscription (com.sun.messaging.jmq.jmsserver.core.Subscription)4 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)4 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)3 MessageDeliveryTimeInfo (com.sun.messaging.jmq.jmsserver.core.MessageDeliveryTimeInfo)3 AccessControlException (java.security.AccessControlException)3 Session (com.sun.messaging.jmq.jmsserver.core.Session)2 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)2 OutOfLimitsException (com.sun.messaging.jmq.util.lists.OutOfLimitsException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 JMSPacket (com.sun.messaging.jmq.io.JMSPacket)1 Packet (com.sun.messaging.jmq.io.Packet)1 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1