Package org.exolab.jms.messagemgr

Examples of org.exolab.jms.messagemgr.ConsumerEndpoint


     * @return the consumer
     * @throws JMSException if the consumer can't be removed
     */
    public ConsumerEndpoint removeConsumer(long consumerId)
            throws JMSException {
        ConsumerEndpoint consumer;
        synchronized (_removeLock) {
            while (consumerId == _consumerId) {
                try {
                    _removeLock.wait();
                } catch (InterruptedException ignore) {
                    // do nothing
                }
            }
            synchronized (this) {
                consumer = (ConsumerEndpoint) _consumers.remove(
                        new Long(consumerId));
                if (consumer == null) {
                    throw new JMSException("No consumer with id=" + consumerId);
                }
                consumer.setListener(null);
            }
            synchronized (_pending) {
                _pending.remove(consumer);
            }
        }
View Full Code Here


     *                   disable
     * @throws JMSException for any JMS error
     */
    public void setAsynchronous(long consumerId, boolean enable)
            throws JMSException {
        ConsumerEndpoint consumer = getConsumer(consumerId);
        consumer.setAsynchronous(enable);
        if (enable && consumer.getMessageCount() != 0) {
            messageAvailable(consumer);
        }

    }
View Full Code Here

    public void start() throws JMSException {
        synchronized (_restartLock) {
            _log.debug("start");
            _stop.set(false);
            for (Iterator i = _consumers.values().iterator(); i.hasNext();) {
                ConsumerEndpoint consumer = (ConsumerEndpoint) i.next();
                if (needsScheduling(consumer)) {
                    queue(consumer);
                }
            }
            try {
View Full Code Here

            condition = new Flag(true);
        }
        if (!_stop.get()) {
            result = doReceive(consumerId, condition);
        } else {
            ConsumerEndpoint consumer = getConsumer(consumerId);
            consumer.setWaitingForMessage(condition);
        }
        return result;
    }
View Full Code Here

     * @param count      the maximum number of messages to receive
     * @return a list of {@link MessageImpl} instances
     * @throws JMSException for any JMS error
     */
    public List browse(long consumerId, int count) throws JMSException {
        ConsumerEndpoint consumer = getConsumer(consumerId);
        if (!(consumer instanceof QueueBrowserEndpoint)) {
            throw new JMSException("Can't browse messages: invalid consumer");
        }

        List messages = new ArrayList(count);

        try {
            _database.begin();
            for (int i = 0; i < count && !_stop.get();) {
                MessageHandle handle = consumer.receive(_stop);
                if (handle == null) {
                    break;
                }
                MessageImpl orig = handle.getMessage();
                if (orig != null) {
View Full Code Here

        };

        _log.debug("dispatch");
        int sent = 0;
        while (sent < MAX_MESSAGES && !done.get()) {
            ConsumerEndpoint consumer;
            synchronized (_pending) {
                if (!_pending.isEmpty()) {
                    consumer = (ConsumerEndpoint) _pending.removeFirst();
                } else {
                    break;
                }
            }
            if (wantsMessages(consumer)) {
                if (consumer.isAsynchronous()) {
                    if (send(consumer, done)) {
                        ++sent;
                    }
                    if (needsScheduling(consumer)) {
                        queue(consumer);
View Full Code Here

        return result;
    }

    private MessageImpl doReceive(long consumerId, final Condition wait)
            throws JMSException {
        ConsumerEndpoint consumer = getConsumer(consumerId);

        Condition cancel;
        if (wait != null) {
            cancel = new Condition() {
                public boolean get() {
                    return _stop.get() || !wait.get();
                }
            };
        } else {
            cancel = _stop;
        }

        MessageImpl message = null;
        try {
            _database.begin();
            MessageHandle handle = consumer.receive(cancel);

            if (handle != null) {
                // retrieve the message and copy it
                message = handle.getMessage();
                if (message != null) {
                    message = copy(message, handle);
                }
            }
            if (message == null) {
                // no message available. Mark the consumer as (possibly) waiting
                // for a message.
                consumer.setWaitingForMessage(wait);
            } else {
                // clear any wait condition
                consumer.setWaitingForMessage(null);

                // if we have a non-null message then add it to the sent message
                // cache. Additionally, if we are part of a global transaction
                // then we must also send it to the ResourceManager for recovery.
                _sent.preSend(handle);
View Full Code Here

     * @return the consumer endpoint corresponding to <code>consumerId</code>
     * @throws JMSException if the consumer doesn't exist
     */
    private ConsumerEndpoint getConsumer(long consumerId)
            throws JMSException {
        ConsumerEndpoint consumer
                = (ConsumerEndpoint) _consumers.get(new Long(consumerId));
        if (consumer == null) {
            throw new JMSException("Consumer not registered: " + consumerId);
        }
        return consumer;
View Full Code Here

        if (destination == null) {
            throw new InvalidDestinationException(
                    "Cannot create MessageConsumer for null destination");
        }

        ConsumerEndpoint consumer = _consumerMgr.createConsumer(
                destination, _connection.getConnectionId(), selector, noLocal);
        _consumer.addConsumer(consumer);
        return consumer.getId();
    }
View Full Code Here

                       + ") [session=" + this + "]");
        }

        // if a durable subscriber with the specified name is
        // already active then this method will throw an exception.
        ConsumerEndpoint consumer = _consumerMgr.createDurableConsumer(topic,
                                                                       name,
                                                                       _connection.getClientID(),
                                                                       _connection.getConnectionId(),
                                                                       noLocal,
                                                                       selector);
        _consumer.addConsumer(consumer);
        return consumer.getId();
    }
View Full Code Here

TOP

Related Classes of org.exolab.jms.messagemgr.ConsumerEndpoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.