Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageId


            // acknowledgment.
            int index = 0;
            boolean inAckRange = false;
            List<MessageReference> removeList = new ArrayList<MessageReference>();
            for (final MessageReference node : dispatched) {
                MessageId messageId = node.getMessageId();
                if (ack.getFirstMessageId() == null
                        || ack.getFirstMessageId().equals(messageId)) {
                    inAckRange = true;
                }
                if (inAckRange) {
                    // Don't remove the nodes until we are committed.
                    if (!context.isInTransaction()) {
                        dequeueCounter++;
                        node.getRegionDestination().getDestinationStatistics()
                                .getDequeues().increment();
                        removeList.add(node);
                    } else {
                        // setup a Synchronization to remove nodes from the
                        // dispatched list.
                        context.getTransaction().addSynchronization(
                                new Synchronization() {

                                    public void afterCommit() throws Exception {
                                        synchronized (PrefetchSubscription.this) {
                                            dequeueCounter++;
                                            dispatched.remove(node);
                                            node.getRegionDestination()
                                                    .getDestinationStatistics()
                                                    .getDequeues().increment();
                                            prefetchExtension--;
                                        }
                                    }

                                    public void afterRollback()
                                            throws Exception {
                                        super.afterRollback();
                                    }
                                });
                    }
                    index++;
                    acknowledge(context, ack, node);
                    if (ack.getLastMessageId().equals(messageId)) {
                        if (context.isInTransaction()) {
                            // extend prefetch window only if not a pulling
                            // consumer
                            if (getPrefetchSize() != 0) {
                                prefetchExtension = Math.max(prefetchExtension,
                                        index + 1);
                            }
                        } else {
                            prefetchExtension = Math.max(0, prefetchExtension
                                    - (index + 1));
                        }
                        callDispatchMatched = true;
                        break;
                    }
                }
            }
            for (final MessageReference node : removeList) {
                dispatched.remove(node);
            }
            // this only happens after a reconnect - get an ack which is not
            // valid
            if (!callDispatchMatched) {
                if (LOG.isDebugEnabled()) {
                    LOG
                            .debug("Could not correlate acknowledgment with dispatched message: "
                                    + ack);
                }
            }
        } else if (ack.isDeliveredAck()) {
            // Message was delivered but not acknowledged: update pre-fetch
            // counters.
            // Acknowledge all dispatched messages up till the message id of the
            // acknowledgment.
            int index = 0;
            for (Iterator<MessageReference> iter = dispatched.iterator(); iter
                    .hasNext(); index++) {
                final MessageReference node = iter.next();
                if (ack.getLastMessageId().equals(node.getMessageId())) {
                    prefetchExtension = Math.max(prefetchExtension, index + 1);
                    callDispatchMatched = true;
                    break;
                }
            }
            if (!callDispatchMatched) {
                throw new JMSException(
                        "Could not correlate acknowledgment with dispatched message: "
                                + ack);
            }
        } else if (ack.isRedeliveredAck()) {
            // Message was re-delivered but it was not yet considered to be a
            // DLQ message.
            // Acknowledge all dispatched messages up till the message id of the
            // acknowledgment.
            boolean inAckRange = false;
            for (final MessageReference node : dispatched) {
                MessageId messageId = node.getMessageId();
                if (ack.getFirstMessageId() == null
                        || ack.getFirstMessageId().equals(messageId)) {
                    inAckRange = true;
                }
                if (inAckRange) {
                    node.incrementRedeliveryCounter();
                    if (ack.getLastMessageId().equals(messageId)) {
                        callDispatchMatched = true;
                        break;
                    }
                }
            }
            if (!callDispatchMatched) {
                throw new JMSException(
                        "Could not correlate acknowledgment with dispatched message: "
                                + ack);
            }
        } else if (ack.isPoisonAck()) {
            // TODO: what if the message is already in a DLQ???
            // Handle the poison ACK case: we need to send the message to a DLQ
            if (ack.isInTransaction()) {
                throw new JMSException("Poison ack cannot be transacted: "
                        + ack);
            }
            // Acknowledge all dispatched messages up till the message id of the
            // acknowledgment.
            int index = 0;
            boolean inAckRange = false;
            List<MessageReference> removeList = new ArrayList<MessageReference>();
            for (final MessageReference node : dispatched) {
                MessageId messageId = node.getMessageId();
                if (ack.getFirstMessageId() == null
                        || ack.getFirstMessageId().equals(messageId)) {
                    inAckRange = true;
                }
                if (inAckRange) {
View Full Code Here


    protected void fireAdvisory(ConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId, ActiveMQMessage advisoryMessage) throws Exception {
        if (getBrokerService().isStarted()) {
            advisoryMessage.setDataStructure(command);
            advisoryMessage.setPersistent(false);
            advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
            advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId()));
            advisoryMessage.setTargetConsumerId(targetConsumerId);
            advisoryMessage.setDestination(topic);
            advisoryMessage.setResponseRequired(false);
            advisoryMessage.setProducerId(advisoryProducerId);
            boolean originalFlowControl = context.isProducerFlowControl();
View Full Code Here

        }
    }

    void recoverNextMessages(int maxReturned, MessageRecoveryListener listener) throws Exception {
        boolean pastLackBatch = lastBatch == null;
        MessageId lastId = null;
        // the message table is a synchronizedMap - so just have to synchronize
        // here
        int count = 0;
        for (Iterator iter = map.entrySet().iterator(); iter.hasNext() && count < maxReturned;) {
            Map.Entry entry = (Entry)iter.next();
View Full Code Here

     * Not synchronized since the Journal has better throughput if you increase
     * the number of concurrent writes that it is doing.
     */
    public void addMessage(ConnectionContext context, final Message message) throws IOException {

        final MessageId id = message.getMessageId();

        final boolean debug = LOG.isDebugEnabled();
        message.incrementReferenceCount();

        final RecordLocation location = peristenceAdapter.writeCommand(message, message.isResponseRequired());
View Full Code Here

    }

    void addMessage(final Message message, final RecordLocation location) {
        synchronized (this) {
            lastLocation = location;
            MessageId id = message.getMessageId();
            messages.put(id, message);
        }
    }
View Full Code Here

    }

    final void removeMessage(final MessageAck ack, final RecordLocation location) {
        synchronized (this) {
            lastLocation = location;
            MessageId id = ack.getLastMessageId();
            Message message = messages.remove(id);
            if (message == null) {
                messageAcks.add(ack);
            } else {
                message.decrementReferenceCount();
View Full Code Here

            addSubscriberMessageContainer(info.getClientId(), info.getSubscriptionName());
        }
    }

    protected MessageId getMessageId(Object object) {
        return new MessageId(((ReferenceRecord)object).getMessageId());
    }
View Full Code Here

    public void stop() {
    }

    protected MessageId getMessageId(Object object) {
        return new MessageId(((ReferenceRecord)object).getMessageId());
    }
View Full Code Here

        throw new RuntimeException("Use addMessageReference instead");
    }

    protected final boolean recoverReference(MessageRecoveryListener listener,
            ReferenceRecord record) throws Exception {
        MessageId id = new MessageId(record.getMessageId());
        if (listener.hasSpace()) {
            listener.recoverMessageReference(id);
            return true;
        }
        return false;
View Full Code Here

    /**
     * Not synchronized since the Journal has better throughput if you increase
     * the number of concurrent writes that it is doing.
     */
    public final void addMessage(ConnectionContext context, final Message message) throws IOException {
        final MessageId id = message.getMessageId();
        final Location location = peristenceAdapter.writeCommand(message, message.isResponseRequired());
        if (!context.isInTransaction()) {
            if (debug) {
                LOG.debug("Journalled message add for: " + id + ", at: " + location);
            }
View Full Code Here

TOP

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

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.