Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageDispatch


            long deadline = 0;
            if (timeout > 0) {
                deadline = System.currentTimeMillis() + timeout;
            }
            while (true) {
                MessageDispatch md = unconsumedMessages.dequeue(timeout);
                if (md == null) {
                    if (timeout > 0 && !unconsumedMessages.isClosed()) {
                        timeout = Math.max(deadline - System.currentTimeMillis(), 0);
                    } else {
                        return null;
                    }
                } else if (md.getMessage() == null) {
                    return null;
                } else if (md.getMessage().isExpired()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(getConsumerId() + " received expired message: " + md);
                    }
                    beforeMessageIsConsumed(md);
                    afterMessageIsConsumed(md, true);
View Full Code Here


    public Message receive() throws JMSException {
        checkClosed();
        checkMessageListener();

        sendPullCommand(0);
        MessageDispatch md = dequeue(-1);
        if (md == null) {
            return null;
        }

        beforeMessageIsConsumed(md);
View Full Code Here

        }

        sendPullCommand(timeout);
        while (timeout > 0) {

            MessageDispatch md;
            if (info.getPrefetchSize() == 0) {
                md = dequeue(-1); // We let the broker let us know when we
                // timeout.
            } else {
                md = dequeue(timeout);
View Full Code Here

    public Message receiveNoWait() throws JMSException {
        checkClosed();
        checkMessageListener();
        sendPullCommand(-1);

        MessageDispatch md;
        if (info.getPrefetchSize() == 0) {
            md = dequeue(-1); // We let the broker let us know when we
            // timeout.
        } else {
            md = dequeue(0);
View Full Code Here

    void deliverAcks() {
        MessageAck ack = null;
        if (deliveryingAcknowledgements.compareAndSet(false, true)) {
            if (this.optimizeAcknowledge) {
                if (!deliveredMessages.isEmpty()) {
                    MessageDispatch md = deliveredMessages.getFirst();
                    ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages.size());
                    deliveredMessages.clear();
                    ackCounter = 0;
                }
            }
View Full Code Here

        if (deliveredMessages.isEmpty()) {
            return;
        }

        // Acknowledge the last message.
        MessageDispatch lastMd = deliveredMessages.get(0);
        MessageAck ack = new MessageAck(lastMd, MessageAck.STANDARD_ACK_TYPE, deliveredMessages.size());
        if (session.isTransacted()) {
            session.doStartTransaction();
            ack.setTransactionId(session.getTransactionContext().getTransactionId());
        }
View Full Code Here

                // remove messages read but not acked at the broker yet through
                // optimizeAcknowledge
                if (!this.info.isBrowser()) {
                    for (int i = 0; (i < deliveredMessages.size()) && (i < ackCounter); i++) {
                        // ensure we don't filter this as a duplicate
                        MessageDispatch md = deliveredMessages.removeLast();
                        session.connection.rollbackDuplicate(this, md.getMessage());
                    }
                }
            }
            if (deliveredMessages.isEmpty()) {
                return;
            }

            // Only increase the redlivery delay after the first redelivery..
            MessageDispatch lastMd = deliveredMessages.getFirst();
            if (lastMd.getMessage().getRedeliveryCounter() > 0) {
                redeliveryDelay = redeliveryPolicy.getRedeliveryDelay(redeliveryDelay);
            }

            for (Iterator iter = deliveredMessages.iterator(); iter.hasNext();) {
                MessageDispatch md = (MessageDispatch)iter.next();
                md.getMessage().onMessageRolledBack();
            }

            if (redeliveryPolicy.getMaximumRedeliveries() != RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES
                && lastMd.getMessage().getRedeliveryCounter() > redeliveryPolicy.getMaximumRedeliveries()) {
                // We need to NACK the messages so that they get sent to the
                // DLQ.
                // Acknowledge the last message.
               
                MessageAck ack = new MessageAck(lastMd, MessageAck.POSION_ACK_TYPE, deliveredMessages.size());
                session.asyncSendPacket(ack);
                // ensure we don't filter this as a duplicate
                session.connection.rollbackDuplicate(this, lastMd.getMessage());
                // Adjust the window size.
                additionalWindowSize = Math.max(0, additionalWindowSize - deliveredMessages.size());
                redeliveryDelay = 0;
            } else {
               
                MessageAck ack = new MessageAck(lastMd, MessageAck.REDELIVERED_ACK_TYPE, deliveredMessages.size());
                session.asyncSendPacket(ack);

                // stop the delivery of messages.
                unconsumedMessages.stop();

                for (Iterator iter = deliveredMessages.iterator(); iter.hasNext();) {
                    MessageDispatch md = (MessageDispatch)iter.next();
                    unconsumedMessages.enqueueFirst(md);
                }

                if (redeliveryDelay > 0) {
                    // Start up the delivery again a little later.
View Full Code Here

     * @throws JMSException
     */
    public boolean iterate() {
        MessageListener listener = this.messageListener;
        if (listener != null) {
            MessageDispatch md = unconsumedMessages.dequeueNoWait();
            if (md != null) {
                try {
                    ActiveMQMessage message = createActiveMQMessage(md);
                    beforeMessageIsConsumed(md);
                    listener.onMessage(message);
View Full Code Here

    }

    protected void serviceRemoteCommand(Command command) {
        try {
            if (command.isMessageDispatch()) {
                MessageDispatch md = (MessageDispatch)command;
                command = md.getMessage();
            }
            if (command.getDataStructureType() == CommandTypes.SHUTDOWN_INFO) {
                LOG.warn("The Master has shutdown");
                shutDown();
            } else {
View Full Code Here

    protected void serviceRemoteCommand(Command command) {
        if (!disposed) {
            try {
                if (command.isMessageDispatch()) {
                    waitStarted();
                    MessageDispatch md = (MessageDispatch)command;
                    serviceRemoteConsumerAdvisory(md.getMessage().getDataStructure());
                    demandConsumerDispatched++;
                    if (demandConsumerDispatched > (demandConsumerInfo.getPrefetchSize() * .75)) {
                        remoteBroker.oneway(new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, demandConsumerDispatched));
                        demandConsumerDispatched = 0;
                    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.command.MessageDispatch

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.