Examples of MessageDispatch


Examples of org.apache.activemq.command.MessageDispatch

                // 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

Examples of org.apache.activemq.command.MessageDispatch

     * @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

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

Examples of org.apache.activemq.command.MessageDispatch

    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

Examples of org.apache.activemq.command.MessageDispatch

            final boolean trace = LOG.isTraceEnabled();
            try {
                if (command.isMessageDispatch()) {
                    enqueueCounter.incrementAndGet();
                    //localStartedLatch.await();
                    final MessageDispatch md = (MessageDispatch)command;
                    DemandSubscription sub = subscriptionMapByLocalId.get(md.getConsumerId());
                    if (sub != null) {
                        Message message = configureMessage(md);
                        if (trace) {
                            LOG.trace("bridging " + configuration.getBrokerName() + " -> " + remoteBrokerName + ": " + message);
                        }

                        if (!message.isResponseRequired()) {

                            // If the message was originally sent using async
                            // send, we will preserve that QOS
                            // by bridging it using an async send (small chance
                            // of message loss).
                            remoteBroker.oneway(message);
                            localBroker.oneway(new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1));
                            dequeueCounter.incrementAndGet();

                        } else {

                            // The message was not sent using async send, so we
                            // should only ack the local
                            // broker when we get confirmation that the remote
                            // broker has received the message.
                            ResponseCallback callback = new ResponseCallback() {
                                public void onCompletion(FutureResponse future) {
                                    try {
                                        Response response = future.getResult();
                                        if (response.isException()) {
                                            ExceptionResponse er = (ExceptionResponse)response;
                                            serviceLocalException(er.getException());
                                        } else {
                                            localBroker.oneway(new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1));
                                            dequeueCounter.incrementAndGet();
                                        }
                                    } catch (IOException e) {
                                        serviceLocalException(e);
                                    }
                                }
                            };

                            remoteBroker.asyncRequest(message, callback);
                        }

                    } else {
                        if (trace) {
                            LOG.trace("No subscription registered with this network bridge for consumerId " + md.getConsumerId() + " for message: " + md.getMessage());
                        }
                    }
                } else if (command.isBrokerInfo()) {
                    localBrokerInfo = (BrokerInfo)command;
                    serviceLocalBrokerInfo(command);
View Full Code Here

Examples of org.apache.activemq.command.MessageDispatch

    }

    private void dispatch(final MessageReference node) throws IOException {
        Message message = (Message)node;
        // 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.decrementReferenceCount();
                }
View Full Code Here

Examples of org.apache.activemq.command.MessageDispatch

        }
        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

Examples of org.apache.activemq.command.MessageDispatch

            return false;
        }
               
        // Make sure we can dispatch a message.
        if (canDispatch(node) && !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);
                if(pending != null) {
                    pending.dispatched(message);
                }
            } 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

Examples of org.apache.activemq.command.MessageDispatch

     * @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

Examples of org.apache.activemq.command.MessageDispatch

                    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
TOP
Copyright © 2018 www.massapi.com. 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.