Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageDispatch


        }

        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

  private MessageAck makeAckForAllDeliveredMessages(byte type) {
    synchronized (deliveredMessages) {
      if (deliveredMessages.isEmpty())
        return null;
         
      MessageDispatch md = deliveredMessages.getFirst();
        MessageAck ack = new MessageAck(md, type, deliveredMessages.size());
        ack.setFirstMessageId(deliveredMessages.getLast().getMessage().getMessageId());
        return ack;
    }
  }
View Full Code Here

                // 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) {
                rollbackPreviouslyDeliveredAndNotRedelivered();
                if (deliveredMessages.isEmpty()) {
                    return;
                }
   
                // use initial delay for first redelivery
                MessageDispatch lastMd = deliveredMessages.getFirst();
                final int currentRedeliveryCount = lastMd.getMessage().getRedeliveryCounter();
                if (currentRedeliveryCount > 0) {
                    redeliveryDelay = redeliveryPolicy.getNextRedeliveryDelay(redeliveryDelay);
                } else {
                    redeliveryDelay = redeliveryPolicy.getInitialRedeliveryDelay();
                }
                MessageId firstMsgId = deliveredMessages.getLast().getMessage().getMessageId();
   
                for (Iterator<MessageDispatch> iter = deliveredMessages.iterator(); iter.hasNext();) {
                    MessageDispatch md = iter.next();
                    md.getMessage().onMessageRolledBack();
                    // ensure we don't filter this as a duplicate
                    session.connection.rollbackDuplicate(this, md.getMessage());
                }
   
                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.setPoisonCause(lastMd.getRollbackCause());
          ack.setFirstMessageId(firstMsgId);
                    session.sendAck(ack,true);
                    // Adjust the window size.
                    additionalWindowSize = Math.max(0, additionalWindowSize - deliveredMessages.size());
                    redeliveryDelay = 0;
                } else {
                   
                    // only redelivery_ack after first delivery
                    if (currentRedeliveryCount > 0) {
                        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<MessageDispatch> iter = deliveredMessages.iterator(); iter.hasNext();) {
                        MessageDispatch md = iter.next();
                        unconsumedMessages.enqueueFirst(md);
                    }
   
                    if (redeliveryDelay > 0 && !unconsumedMessages.isClosed()) {
                        // Start up the delivery again a little later.
View Full Code Here

     * called with deliveredMessages locked
     */
    private void removeFromDeliveredMessages(MessageId key) {
        Iterator<MessageDispatch> iterator = deliveredMessages.iterator();
        while (iterator.hasNext()) {
            MessageDispatch candidate = iterator.next();
            if (key.equals(candidate.getMessage().getMessageId())) {
                session.connection.rollbackDuplicate(this, candidate.getMessage());
                iterator.remove();
                break;
            }
        }
    }
View Full Code Here

     * @throws JMSException
     */
    public boolean iterate() {
        MessageListener listener = this.messageListener.get();
        if (listener != null) {
            MessageDispatch md = unconsumedMessages.dequeueNoWait();
            if (md != null) {
                dispatch(md);
                return true;
            }
        }
View Full Code Here

    public String marshalText(Object command) throws IOException {
        if (command instanceof MarshallAware) {
            ((MarshallAware)command).beforeMarshall(this);
        } else if(command instanceof MessageDispatch) {
            MessageDispatch dispatch = (MessageDispatch) command;
            if (dispatch != null && dispatch.getMessage() != null) {
                dispatch.getMessage().beforeMarshall(this);
            }
        }

        return getXStream().toXML(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

    synchronized void onStompCommit(TransactionId transactionId) {
      for (Iterator iter = dispatchedMessage.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Entry)iter.next();
            MessageId id = (MessageId)entry.getKey();
            MessageDispatch msg = (MessageDispatch)entry.getValue();
            if (unconsumedMessage.contains(msg)) {
              iter.remove();
            }
      }
      unconsumedMessage.clear();
View Full Code Here

            int count = 0;
            for (Iterator iter = dispatchedMessage.entrySet().iterator(); iter.hasNext();) {

                Map.Entry entry = (Entry)iter.next();
                MessageId id = (MessageId)entry.getKey();
                MessageDispatch msg = (MessageDispatch)entry.getValue();

                if (ack.getFirstMessageId() == null) {
                    ack.setFirstMessageId(id);
                }
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.