Package org.apache.activemq.command

Examples of org.apache.activemq.command.MessageId


     * 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

        String stompTx = headers.get(Stomp.Headers.TRANSACTION);

        ActiveMQMessage message = convertMessage(command);

        message.setProducerId(producerId);
        MessageId id = new MessageId(producerId, messageIdGenerator.getNextSequenceId());
        message.setMessageId(id);
        message.setJMSTimestamp(System.currentTimeMillis());

        if (stompTx != null) {
            TransactionId activemqTx = transactions.get(stompTx);
View Full Code Here

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

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

                    msg.getMessageId().setBrokerSequenceId(sequenceId);
                    return listener.recoverMessage(msg);
                }

                public boolean recoverMessageReference(String reference) throws Exception {
                    return listener.recoverMessageReference(new MessageId(reference));
                }
            });
        } catch (SQLException e) {
            JDBCPersistenceAdapter.log("JDBC Failure: ", e);
            throw IOExceptionSupport.create("Failed to recover container. Reason: " + e, e);
View Full Code Here

                    return false;
                }

                public boolean recoverMessageReference(String reference) throws Exception {
                    if (listener.hasSpace()) {
                        listener.recoverMessageReference(new MessageId(reference));
                        return true;
                    }
                    return false;
                }
View Full Code Here

                // 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) {
                        // Don't remove the nodes until we are committed.
                        removeList.add(node);
                        if (!context.isInTransaction()) {
                            dequeueCounter++;
                            if (!this.getConsumerInfo().isBrowser()) {
                                node.getRegionDestination().getDestinationStatistics().getDequeues().increment();
                            }
                            node.getRegionDestination().getDestinationStatistics().getInflight().decrement();
                        } else {
                            // setup a Synchronization to remove nodes from the
                            // dispatched list.
                            context.getTransaction().addSynchronization(
                                    new Synchronization() {

                                        public void afterCommit()
                                                throws Exception {
                                            synchronized(dispatchLock) {
                                                dequeueCounter++;
                                                node.getRegionDestination().getDestinationStatistics().getDequeues().increment();
                                                node.getRegionDestination().getDestinationStatistics().getInflight().decrement();
                                                prefetchExtension--;
                                            }
                                        }

                                        public void afterRollback() throws Exception {
                                          // Need to put it back in the front.
                                            synchronized(dispatchLock) {
                                              dispatched.add(0, node);
                                              // ActiveMQ workaround for AMQ-1730 - Please Ignore next line
                                                node.incrementRedeliveryCounter();
                                                node.getRegionDestination().getDestinationStatistics().getInflight().decrement();
                                            }
                                        }
                                    });
                        }
                        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));
                            }
                            destination = node.getRegionDestination();
                            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) {
                        LOG.error("Could not correlate acknowledgment with dispatched message: "
                                  + ack);
                }
            } else if (ack.isIndividualAck()) {
                // Message was delivered and acknowledge - but only delete the
                // individual message
                for (final MessageReference node : dispatched) {
                    MessageId messageId = node.getMessageId();
                    if (ack.getLastMessageId().equals(messageId)) {
                        // this should never be within a transaction
                        node.getRegionDestination().getDestinationStatistics().getDequeues().increment();
                        node.getRegionDestination().getDestinationStatistics().getInflight().decrement();
                        destination = node.getRegionDestination();
                        acknowledge(context, ack, node);
                        dispatched.remove(node);
                        prefetchExtension = Math.max(0, prefetchExtension - 1);
                        callDispatchMatched = true;
                        break;
                    }
                }
            }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( node.isExpired() ) {
                        node.getRegionDestination().messageExpired(context, this, node);
                        dispatched.remove(node);
                    }
                    if (ack.getLastMessageId().equals(node.getMessageId())) {
                        prefetchExtension = Math.max(prefetchExtension, index + 1);
                        destination = node.getRegionDestination();
                        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)) {
                            destination = node.getRegionDestination();
                            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

     * @param firstAckedMsg
     * @param lastAckedMsg
     * @throws JMSException if it does not match
     */
  protected void assertAckMatchesDispatched(MessageAck ack) throws JMSException {
        MessageId firstAckedMsg = ack.getFirstMessageId();
        MessageId lastAckedMsg = ack.getLastMessageId();
        int checkCount = 0;
        boolean checkFoundStart = false;
        boolean checkFoundEnd = false;
        for (MessageReference node : dispatched) {

            if (firstAckedMsg == null) {
                checkFoundStart = true;
            } else if (!checkFoundStart && firstAckedMsg.equals(node.getMessageId())) {
                checkFoundStart = true;
            }

            if (checkFoundStart) {
                checkCount++;
            }

            if (lastAckedMsg != null && lastAckedMsg.equals(node.getMessageId())) {
                checkFoundEnd = true;
                break;
            }
        }
        if (!checkFoundStart && firstAckedMsg != null)
View Full Code Here

        }
        return l.toArray(new Message[l.size()]);
    }

    public Message getMessage(String id) {
        MessageId msgId = new MessageId(id);
        try {
            synchronized (pagedInMessages) {
                QueueMessageReference r = this.pagedInMessages.get(msgId);
                if (r != null) {
                    return r.getMessage();
                }
            }
            synchronized (messages) {
                try {
                    messages.reset();
                    while (messages.hasNext()) {
                        try {
                            MessageReference r = messages.next();
                            messages.rollback(r.getMessageId());
                            if (msgId.equals(r.getMessageId())) {
                                Message m = r.getMessage();
                                if (m != null) {
                                    return m;
                                }
                                break;
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.