Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageDispatch


                // optimizeAcknowledge
                if (!this.info.isBrowser()) {
                    synchronized(deliveredMessages) {
                        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());
                        }
                    }
                }
            }
            synchronized(deliveredMessages) {
                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);
                }
                MessageId firstMsgId = deliveredMessages.getLast().getMessage().getMessageId();
   
                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());
          ack.setFirstMessageId(firstMsgId);
                    session.sendAck(ack,true);
                    // 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());
                    ack.setFirstMessageId(firstMsgId);
                    session.sendAck(ack,true);
   
                    // 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.get();
        if (listener != null) {
            MessageDispatch md = unconsumedMessages.dequeueNoWait();
            if (md != null) {
                try {
                    ActiveMQMessage message = createActiveMQMessage(md);
                    beforeMessageIsConsumed(md);
                    listener.onMessage(message);
View Full Code Here

        // Now get the messages.
        Object m = connection.getDispatchQueue().poll(maxWait, TimeUnit.MILLISECONDS);
        int i = 0;
        while (m != null) {
            if (m instanceof MessageDispatch && ((MessageDispatch)m).getConsumerId().equals(consumerInfo.getConsumerId())) {
                MessageDispatch md = (MessageDispatch)m;
                if (md.getMessage() != null) {
                    i++;
                    connection.send(createAck(consumerInfo, md.getMessage(), 1, MessageAck.STANDARD_ACK_TYPE));
                } else {
                    break;
                }
            } else {
                skipped.add(m);
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

    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

            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 && md.getMessage()!=null) {
                     
                        // See if this consumer's brokerPath tells us it came from the broker at the other end
                        // of the bridge. I think we should be making this decision based on the message's
                        // broker bread crumbs and not the consumer's? However, the message's broker bread
                        // crumbs are null, which is another matter.  
                        boolean cameFromRemote = false;
                        Object consumerInfo = md.getMessage().getDataStructure();
                        if( consumerInfo != null && (consumerInfo instanceof ConsumerInfo) )                                          
                          cameFromRemote = contains( ((ConsumerInfo)consumerInfo).getBrokerPath(),remoteBrokerInfo.getBrokerId());                                                
                                                                    
                        Message message = configureMessage(md);
                        if (trace) {
                            LOG.trace("bridging " + configuration.getBrokerName() + " -> " + remoteBrokerName + ": " + message);
                            LOG.trace("cameFromRemote = "+cameFromRemote + ", repsonseRequired = " + message.isResponseRequired());   
                        }

                        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).
                           
                            // Don't send it off to the remote if it originally came from the remote.
                            if( !cameFromRemote ) {
                               remoteBroker.oneway(message);
                              }
                            else{
                              LOG.info("Message not forwarded on to remote, because message came from remote");                              
                            }
                            localBroker.oneway(new MessageAck(md, MessageAck.INDIVIDUAL_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.INDIVIDUAL_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

                    handleException(exception, null);
                }
            }
        } else if (command.isMessageDispatch()) {

            MessageDispatch md = (MessageDispatch)command;
            StompSubscription sub = subscriptionsByConsumerId.get(md.getConsumerId());
            if (sub != null) {
                sub.onMessageDispatch(md);
            }
        } else if (command.getDataStructureType() == ConnectionError.DATA_STRUCTURE_TYPE) {
            // Pass down any unexpected async errors. Should this close the connection?
View Full Code Here

            return false;
        }
        // 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

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.