Search in sources :

Example 6 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 7 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)

Example 8 with SelectorFormatException

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

the class ProtocolImpl method verifyDestination.

/**
 * Verify a destination exists.
 *
 * @param destination destination name
 * @param type DestType of the destination
 * @param selectorstr selector string to verify or null if none
 * @see com.sun.messaging.jmq.util.DestType
 * @return a hashmap which contains the following entries:
 * <UL>
 * <LI>JMQStatus</LI>
 * <LI>JMQCanCreate</LI>
 * <LI>DestType</LI>
 * </UL>
 */
@Override
public HashMap verifyDestination(String destination, int type, String selectorstr) throws /* may be null */
BrokerException, IOException {
    HashMap returnmap = new HashMap();
    try {
        if (selectorstr != null) {
            Selector.compile(selectorstr);
        }
    } catch (SelectorFormatException ex) {
        returnmap.put("JMQStatus", Integer.valueOf(Status.BAD_REQUEST));
        return returnmap;
    }
    Destination[] ds = DL.getDestination(null, destination, DestType.isQueue(type));
    Destination d = ds[0];
    if (d == null) {
        returnmap.put("JMQCanCreate", Boolean.valueOf(DL.canAutoCreate(DestType.isQueue(type))));
        returnmap.put("JMQStatus", Integer.valueOf(Status.NOT_FOUND));
    } else {
        returnmap.put("JMQDestType", Integer.valueOf(d.getType()));
        returnmap.put("JMQStatus", Integer.valueOf(Status.OK));
    }
    return returnmap;
}
Also used : SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with SelectorFormatException

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

the class BrokerConsumers method addConsumer.

public void addConsumer(Consumer c) throws BrokerException {
    if (getDEBUG()) {
        logger.log(logger.INFO, "BrokerConsumers.addConsumer: " + c);
    }
    com.sun.messaging.jmq.jmsserver.core.ConsumerUID cuid = c.getConsumerUID();
    if (consumers.get(cuid) != null) {
        String emsg = Globals.getBrokerResources().getKString(BrokerResources.I_CONSUMER_ALREADY_ADDED, cuid, c.getDestinationUID());
        logger.log(logger.INFO, emsg + " (CLUSTER_ROUTER)");
        throw new ConsumerAlreadyAddedException(emsg);
    }
    DL.acquirePartitionLock(true);
    try {
        if (!(c instanceof Subscription)) {
            consumers.put(cuid, c);
            pendingConsumerUIDs.put(cuid, null);
            listeners.put(cuid, c.addEventListener(this, EventType.BUSY_STATE_CHANGED, null));
        }
        DestinationUID duid = c.getDestinationUID();
        int type = (duid.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
        Destination d = null;
        try {
            if (!duid.isWildcard()) {
                for (int i = 0; i < 2; i++) {
                    Destination[] ds = DL.getDestination(Globals.getStore().getPrimaryPartition(), duid.getName(), type, true, true);
                    d = ds[0];
                    try {
                        // is not removed by autocreate prematurely
                        if (d != null) {
                            d.incrementRefCount();
                            // well we should break anyway, but
                            break;
                        // this makes it explicit
                        }
                    } catch (BrokerException ex) {
                        // incrementRefCount throws a BrokerException
                        // if the destination was destroyed
                        // if we are here then the destination went away
                        // try to get the destination again
                        d = null;
                    }
                }
                if (d == null) {
                    throw new BrokerException("Unable to attach to destination " + duid);
                }
            }
        } catch (IOException ex) {
            throw new BrokerException("Unable to autocreate destination " + duid, ex);
        }
        try {
            // before we exit (so cleanup can occur)
            if (!c.getDestinationUID().isQueue() && (!(c instanceof Subscription)) && c.getSubscription() == null) {
                // directly send messages
                c.setFalconRemote(true);
            } else {
                int mp = (d == null ? -1 : d.getMaxPrefetch());
                if (mp <= 0 || mp > BTOBFLOW) {
                    mp = BTOBFLOW;
                }
                int prefetch = c.getRemotePrefetch();
                if (prefetch <= 0 || prefetch > mp) {
                    prefetch = mp;
                }
                Subscription sub = c.getSubscription();
                if (sub != null && sub.getShared()) {
                    prefetch = 1;
                }
                c.setPrefetch(prefetch);
            }
            try {
                if (d == null && c.getSubscription() == null) {
                    // deal with wildcard subscription
                    Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, c.getDestinationUID());
                    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 {
                                dd.addConsumer(c, false);
                            } catch (ConsumerAlreadyAddedException e) {
                                logger.log(logger.INFO, e.getMessage() + " (CLUSTER_ROUTER)");
                            }
                        }
                    }
                } else if (c.getSubscription() == null) {
                    Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, c.getDestinationUID());
                    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 {
                                dd.addConsumer(c, false);
                            } catch (ConsumerAlreadyAddedException e) {
                                logger.log(logger.INFO, e.getMessage() + " (CLUSTER_ROUTER)");
                            }
                        }
                    }
                }
            } catch (SelectorFormatException ex) {
                throw new BrokerException("unable to add destination " + d, ex);
            }
            if (!(c instanceof Subscription)) {
                if (c.isBusy()) {
                    synchronized (activeConsumers) {
                        activeConsumers.add(c);
                        activeConsumers.notifyAll();
                    }
                }
            }
        } finally {
            // processing the add consumer
            if (d != null) {
                // not wildcard
                d.decrementRefCount();
            }
        }
    } finally {
        DL.releasePartitionLock(true);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Iterator(java.util.Iterator) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 10 with SelectorFormatException

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

the class ClusterConsumerInfo method readConsumer.

public static Consumer readConsumer(DataInputStream dis) throws IOException {
    Logger logger = Globals.getLogger();
    ConsumerUID id = null;
    String destName = null;
    String clientID = null;
    String durableName = null;
    String selstr = null;
    boolean isQueue;
    boolean noLocalDelivery;
    // boolean consumerReady;
    int sharedcnt;
    int position;
    // version
    long ver = dis.readLong();
    if (ver != ConsumerVersionUID) {
        throw new IOException("Wrong Consumer Version " + ver + " expected " + ConsumerVersionUID);
    }
    destName = dis.readUTF();
    boolean hasId = dis.readBoolean();
    if (hasId) {
        id = readConsumerUID(dis);
    }
    boolean hasClientID = dis.readBoolean();
    if (hasClientID) {
        clientID = dis.readUTF();
    }
    boolean hasDurableName = dis.readBoolean();
    if (hasDurableName) {
        durableName = dis.readUTF();
    }
    boolean hasSelector = dis.readBoolean();
    if (hasSelector) {
        selstr = dis.readUTF();
    }
    isQueue = dis.readBoolean();
    noLocalDelivery = dis.readBoolean();
    // consumerReady = dis.readBoolean();
    dis.readBoolean();
    boolean sharedSet = false;
    sharedcnt = 1;
    try {
        sharedSet = dis.readBoolean();
        if (sharedSet == true) {
            sharedcnt = dis.readInt();
        }
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    position = -1;
    try {
        position = dis.readInt();
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    // 5.0
    boolean jmsshare = false;
    String ndsubname = null;
    try {
        jmsshare = dis.readBoolean();
        boolean hasndsubname = dis.readBoolean();
        if (hasndsubname) {
            ndsubname = dis.readUTF();
        }
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    try {
        DestinationUID dest = DestinationUID.getUID(destName, isQueue);
        if (durableName != null) {
            Subscription sub = Subscription.findCreateDurableSubscription(clientID, durableName, (sharedcnt != 1), jmsshare, dest, selstr, noLocalDelivery, false, id, Integer.valueOf(sharedcnt));
            return sub;
        } else {
            if (sharedSet) {
                /* non-durable subscriber */
                Subscription sub = Subscription.findCreateNonDurableSubscription(clientID, selstr, ndsubname, (sharedcnt != 1), jmsshare, dest, noLocalDelivery, id, Integer.valueOf(sharedcnt));
                return sub;
            } else {
                Consumer c = Consumer.newConsumer(dest, selstr, noLocalDelivery, id);
                c.setLockPosition(position);
                return c;
            }
        }
    } catch (SelectorFormatException ex) {
        logger.logStack(Logger.WARNING, "Got bad selector[" + selstr + "] ", ex);
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    } catch (BrokerException ex) {
        if (ex.getStatusCode() == Status.CONFLICT || ex instanceof ConsumerAlreadyAddedException) {
            logger.log(Logger.WARNING, ex.getMessage());
        } else {
            logger.logStack(Logger.WARNING, ex.getMessage(), ex);
        }
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) Logger(com.sun.messaging.jmq.util.log.Logger) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription)

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