Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageDispatch


    }

    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


                    Thread.currentThread().interrupt();
                }
            }
        } else {
            if (message.isMessageDispatch()) {
                MessageDispatch md = (MessageDispatch) message;
                Runnable sub = md.getTransmitCallback();
                broker.postProcessDispatch(md);
                if (sub != null) {
                    sub.run();
                }
            }
View Full Code Here

            }
        }
    }

    protected void processDispatch(Command command) throws IOException {
        final MessageDispatch messageDispatch = (MessageDispatch) (command.isMessageDispatch() ? command : null);
        try {
            if (!stopping.get()) {
                if (messageDispatch != null) {
                    broker.preProcessDispatch(messageDispatch);
                }
                dispatch(command);
            }
        } finally {
            if (messageDispatch != null) {
                Runnable sub = messageDispatch.getTransmitCallback();
                broker.postProcessDispatch(messageDispatch);
                if (sub != null) {
                    sub.run();
                }
            }
View Full Code Here

        // cleaned up.
        synchronized (dispatchQueue) {
            for (Iterator<Command> iter = dispatchQueue.iterator(); iter.hasNext();) {
                Command command = iter.next();
                if (command.isMessageDispatch()) {
                    MessageDispatch md = (MessageDispatch) command;
                    Runnable sub = md.getTransmitCallback();
                    broker.postProcessDispatch(md);
                    if (sub != null) {
                        sub.run();
                    }
                }
View Full Code Here

    private void dispatch(final MessageReference node) throws IOException {
        Message message = (Message)node;
        node.incrementReferenceCount();
        // Make sure we can dispatch a message.
        MessageDispatch md = new MessageDispatch();
        md.setMessage(message);
        md.setConsumerId(info.getConsumerId());
        md.setDestination(node.getRegionDestination().getActiveMQDestination());
        dispatchedCounter.incrementAndGet();
        // Keep track if this subscription is receiving messages from a single
        // destination.
        if (singleDestination) {
            if (destination == null) {
                destination = node.getRegionDestination();
            } else {
                if (destination != node.getRegionDestination()) {
                    singleDestination = false;
                }
            }
        }
        if (info.isDispatchAsync()) {
            md.setTransmitCallback(new Runnable() {

                public void run() {
                    node.getRegionDestination().getDestinationStatistics().getDispatched().increment();
                    node.getRegionDestination().getDestinationStatistics().getInflight().increment();
                    node.decrementReferenceCount();
View Full Code Here

        okForAckAsDispatchDone.countDown();
       
        // No reentrant lock - Patch needed to IndirectMessageReference on method lock
        if (!isSlave()) {

            MessageDispatch md = createMessageDispatch(node, message);
            // NULL messages don't count... they don't get Acked.
            if (node != QueueMessageReference.NULL_MESSAGE) {
                dispatchCounter++;
                dispatched.add(node);
            } else {
                prefetchExtension = Math.max(0, prefetchExtension - 1);
            }
            if (info.isDispatchAsync()) {
                md.setTransmitCallback(new Runnable() {

                    public void run() {
                        // Since the message gets queued up in async dispatch,
                        // we don't want to
                        // decrease the reference count until it gets put on the
View Full Code Here

     * @param message
     * @return MessageDispatch
     */
    protected MessageDispatch createMessageDispatch(MessageReference node, Message message) {
        if (node == QueueMessageReference.NULL_MESSAGE) {
            MessageDispatch md = new MessageDispatch();
            md.setMessage(null);
            md.setConsumerId(info.getConsumerId());
            md.setDestination(null);
            return md;
        } else {
            MessageDispatch md = new MessageDispatch();
            md.setConsumerId(info.getConsumerId());
            md.setDestination(node.getRegionDestination().getActiveMQDestination());
            md.setMessage(message);
            md.setRedeliveryCounter(node.getRedeliveryCounter());
            return md;
        }
    }
View Full Code Here

        prefetchExtension = 0;
    }

   
    protected MessageDispatch createMessageDispatch(MessageReference node, Message message) {
        MessageDispatch md = super.createMessageDispatch(node, message);
        Integer count = redeliveredMessages.get(node.getMessageId());
        if (count != null) {
            md.setRedeliveryCounter(count.intValue());
        }
        return md;
    }
View Full Code Here

            if (o == null) {
                return null;
            }
            if (o instanceof MessageDispatch) {

                MessageDispatch dispatch = (MessageDispatch)o;
                if (dispatch.getMessage() == null) {
                    return null;
                }
                dispatch.setMessage(dispatch.getMessage().copy());
                dispatch.getMessage().setRedeliveryCounter(dispatch.getRedeliveryCounter());
                return dispatch.getMessage();
            }
        }
    }
View Full Code Here

     * by ordinary JMS clients.
     *
     * @see javax.jms.ServerSession
     */
    public void run() {
        MessageDispatch messageDispatch;
        while ((messageDispatch = executor.dequeueNoWait()) != null) {
            final MessageDispatch md = messageDispatch;
            ActiveMQMessage message = (ActiveMQMessage)md.getMessage();
            if (message.isExpired() || connection.isDuplicate(ActiveMQSession.this, message)) {
                // TODO: Ack it without delivery to client
                continue;
            }

            if (isClientAcknowledge()||isIndividualAcknowledge()) {
                message.setAcknowledgeCallback(new Callback() {
                    public void execute() throws Exception {
                    }
                });
            }

            if (deliveryListener != null) {
                deliveryListener.beforeDelivery(this, message);
            }

            md.setDeliverySequenceId(getNextDeliveryId());

            try {
                messageListener.onMessage(message);
            } catch (RuntimeException e) {
                LOG.error("error dispatching message: ", e);
                // A problem while invoking the MessageListener does not
                // in general indicate a problem with the connection to the broker, i.e.
                // it will usually be sufficient to let the afterDelivery() method either
                // commit or roll back in order to deal with the exception.
                // However, we notify any registered client internal exception listener
                // of the problem.
                connection.onClientInternalException(e);
            }

            try {
                MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1);
                ack.setFirstMessageId(md.getMessage().getMessageId());
                doStartTransaction();
                ack.setTransactionId(getTransactionContext().getTransactionId());
                if (ack.getTransactionId() != null) {
                    getTransactionContext().addSynchronization(new Synchronization() {

                        @Override
                        public void afterRollback() throws Exception {
                            md.getMessage().onMessageRolledBack();
                            // ensure we don't filter this as a duplicate
                            connection.rollbackDuplicate(ActiveMQSession.this, md.getMessage());
                            RedeliveryPolicy redeliveryPolicy = connection.getRedeliveryPolicy();
                            int redeliveryCounter = md.getMessage().getRedeliveryCounter();
                            if (redeliveryPolicy.getMaximumRedeliveries() != RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES
                                && redeliveryCounter > redeliveryPolicy.getMaximumRedeliveries()) {
                                // We need to NACK the messages so that they get
                                // sent to the
                                // DLQ.
                                // Acknowledge the last message.
                                MessageAck ack = new MessageAck(md, MessageAck.POSION_ACK_TYPE, 1);
                                ack.setFirstMessageId(md.getMessage().getMessageId());
                                asyncSendPacket(ack);
                            } else {
                               
                                MessageAck ack = new MessageAck(md, MessageAck.REDELIVERED_ACK_TYPE, 1);
                                ack.setFirstMessageId(md.getMessage().getMessageId());
                                asyncSendPacket(ack);

                                // Figure out how long we should wait to resend
                                // this message.
                                long redeliveryDelay = redeliveryPolicy.getInitialRedeliveryDelay();
                                for (int i = 0; i < redeliveryCounter; i++) {
                                    redeliveryDelay = redeliveryPolicy.getNextRedeliveryDelay(redeliveryDelay);
                                }
                                scheduler.executeAfterDelay(new Runnable() {

                                    public void run() {
                                        ((ActiveMQDispatcher)md.getConsumer()).dispatch(md);
                                    }
                                }, redeliveryDelay);
                            }
                        }
                    });
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.