Search in sources :

Example 1 with MessageContainer

use of org.apache.qpid.server.message.MessageContainer in project qpid-broker-j by apache.

the class AbstractQueue method deliverSingleMessage.

MessageContainer deliverSingleMessage(QueueConsumer<?, ?> consumer) {
    boolean queueEmpty = false;
    MessageContainer messageContainer = null;
    _queueConsumerManager.setNotified(consumer, false);
    try {
        if (!consumer.isSuspended()) {
            messageContainer = attemptDelivery(consumer);
            if (messageContainer.getMessageInstance() == null) {
                if (consumer.acquires()) {
                    if (hasAvailableMessages()) {
                        notifyOtherConsumers(consumer);
                    }
                }
                consumer.noMessagesAvailable();
                messageContainer = null;
            } else {
                _queueConsumerManager.setNotified(consumer, true);
            }
        } else {
            // avoid referring old deleted queue entry in sub._queueContext._lastSeen
            getNextAvailableEntry(consumer);
        }
    } finally {
        consumer.flushBatched();
    }
    return messageContainer;
}
Also used : MessageContainer(org.apache.qpid.server.message.MessageContainer)

Example 2 with MessageContainer

use of org.apache.qpid.server.message.MessageContainer in project qpid-broker-j by apache.

the class TrustStoreMessageSourceTest method testAddConsumer.

public void testAddConsumer() throws Exception {
    final EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
    final ConsumerTarget target = mock(ConsumerTarget.class);
    when(target.allocateCredit(any(ServerMessage.class))).thenReturn(true);
    MessageInstanceConsumer consumer = _trustStoreMessageSource.addConsumer(target, null, ServerMessage.class, getTestName(), options, 0);
    final MessageContainer messageContainer = consumer.pullMessage();
    assertNotNull("Could not pull message of TrustStore", messageContainer);
    final ServerMessage message = messageContainer.getMessageInstance().getMessage();
    assertCertificates(getCertificatesFromMessage(message));
}
Also used : MessageContainer(org.apache.qpid.server.message.MessageContainer) ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) ConsumerTarget(org.apache.qpid.server.consumer.ConsumerTarget) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer)

Example 3 with MessageContainer

use of org.apache.qpid.server.message.MessageContainer in project qpid-broker-j by apache.

the class AbstractQueue method attemptDelivery.

/**
 * Attempt delivery for the given consumer.
 *
 * Looks up the next node for the consumer and attempts to deliver it.
 *
 * @param sub the consumer
 * @return true if we have completed all possible deliveries for this sub.
 */
private MessageContainer attemptDelivery(QueueConsumer<?, ?> sub) {
    // avoid referring old deleted queue entry in sub._queueContext._lastSeen
    QueueEntry node = getNextAvailableEntry(sub);
    boolean subActive = sub.isActive() && !sub.isSuspended();
    if (node != null && subActive && (sub.getPriority() == Integer.MAX_VALUE || noHigherPriorityWithCredit(sub, node))) {
        if (_virtualHost.getState() != State.ACTIVE) {
            throw new ConnectionScopedRuntimeException("Delivery halted owing to " + "virtualhost state " + _virtualHost.getState());
        }
        if (node.isAvailable() && mightAssign(sub, node)) {
            if (sub.allocateCredit(node)) {
                MessageReference messageReference = null;
                if ((sub.acquires() && !assign(sub, node)) || (!sub.acquires() && (messageReference = node.newMessageReference()) == null)) {
                    // restore credit here that would have been taken away by allocateCredit since we didn't manage
                    // to acquire the entry for this consumer
                    sub.restoreCredit(node);
                } else {
                    setLastSeenEntry(sub, node);
                    return new MessageContainer(node, messageReference);
                }
            } else {
                sub.awaitCredit(node);
            }
        }
    }
    return NO_MESSAGES;
}
Also used : MessageContainer(org.apache.qpid.server.message.MessageContainer) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 4 with MessageContainer

use of org.apache.qpid.server.message.MessageContainer in project qpid-broker-j by apache.

the class QueueConsumerImpl method pullMessage.

@Override
public MessageContainer pullMessage() {
    MessageContainer messageContainer = _queue.deliverSingleMessage(this);
    if (messageContainer != null) {
        _deliveredCount.incrementAndGet();
        _deliveredBytes.addAndGet(messageContainer.getMessageInstance().getMessage().getSizeIncludingHeader());
    }
    return messageContainer;
}
Also used : MessageContainer(org.apache.qpid.server.message.MessageContainer)

Example 5 with MessageContainer

use of org.apache.qpid.server.message.MessageContainer in project qpid-broker-j by apache.

the class AbstractConsumerTarget method sendNextMessage.

@Override
public boolean sendNextMessage() {
    MessageContainer messageContainer = null;
    MessageInstanceConsumer consumer = null;
    boolean iteratedCompleteList = false;
    while (messageContainer == null) {
        if (_pullIterator == null || !_pullIterator.hasNext()) {
            if (iteratedCompleteList) {
                break;
            }
            iteratedCompleteList = true;
            _pullIterator = getConsumers().iterator();
        }
        if (_pullIterator.hasNext()) {
            consumer = _pullIterator.next();
            messageContainer = consumer.pullMessage();
        }
    }
    if (messageContainer != null) {
        MessageInstance entry = messageContainer.getMessageInstance();
        try {
            send(consumer, entry, false);
        } catch (MessageConversionException mce) {
            restoreCredit(entry.getMessage());
            final TransactionLogResource owningResource = entry.getOwningResource();
            if (owningResource instanceof MessageSource) {
                final MessageSource.MessageConversionExceptionHandlingPolicy handlingPolicy = ((MessageSource) owningResource).getMessageConversionExceptionHandlingPolicy();
                switch(handlingPolicy) {
                    case CLOSE:
                        entry.release(consumer);
                        throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
                    case ROUTE_TO_ALTERNATE:
                        if (consumer.acquires()) {
                            int enqueues = entry.routeToAlternate(null, null);
                            if (enqueues == 0) {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message discarded.", entry.getMessage(), mce.getMessage());
                            } else {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message routed to alternate.", entry.getMessage(), mce.getMessage());
                            }
                        } else {
                            LOGGER.info("Failed to convert message {} for this browser because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        }
                        break;
                    case REJECT:
                        entry.reject(consumer);
                        entry.release(consumer);
                        LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        break;
                    default:
                        throw new ServerScopedRuntimeException("Unrecognised policy " + handlingPolicy);
                }
            } else {
                throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
            }
        } finally {
            if (messageContainer.getMessageReference() != null) {
                messageContainer.getMessageReference().release();
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageContainer(org.apache.qpid.server.message.MessageContainer) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

MessageContainer (org.apache.qpid.server.message.MessageContainer)8 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)4 ConsumerOption (org.apache.qpid.server.consumer.ConsumerOption)2 ConsumerTarget (org.apache.qpid.server.consumer.ConsumerTarget)2 MessageInstance (org.apache.qpid.server.message.MessageInstance)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 MessageSource (org.apache.qpid.server.message.MessageSource)2 ServerMessage (org.apache.qpid.server.message.ServerMessage)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 Consumer (org.apache.qpid.server.model.Consumer)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)1 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)1