Search in sources :

Example 1 with MessageInstanceConsumer

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

the class AbstractConsumerTarget method close.

@Override
public final boolean close() {
    if (_state.compareAndSet(State.OPEN, State.CLOSED)) {
        setNotifyWorkDesired(false);
        List<MessageInstanceConsumer> consumers = new ArrayList<>(_consumers);
        _consumers.clear();
        for (MessageInstanceConsumer consumer : consumers) {
            consumer.close();
        }
        getSession().removeTicker(_suspendedConsumerLoggingTicker);
        return true;
    } else {
        return false;
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer)

Example 2 with MessageInstanceConsumer

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

the class AbstractConsumerTarget method setNotifyWorkDesired.

protected final void setNotifyWorkDesired(final boolean desired) {
    if (desired != _notifyWorkDesired) {
        if (desired) {
            getSession().removeTicker(_suspendedConsumerLoggingTicker);
        } else {
            _suspendedConsumerLoggingTicker.setStartTime(System.currentTimeMillis());
            getSession().addTicker(_suspendedConsumerLoggingTicker);
        }
        for (MessageInstanceConsumer consumer : _consumers) {
            consumer.setNotifyWorkDesired(desired);
        }
        _notifyWorkDesired = desired;
    }
}
Also used : MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer)

Example 3 with MessageInstanceConsumer

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

the class AMQChannel method requeue.

/**
 * Called to attempt re-delivery all outstanding unacknowledged messages on the channel. May result in delivery to
 * this same channel or to other subscribers.
 */
private void requeue() {
    final Map<Long, MessageConsumerAssociation> copy = new LinkedHashMap<>();
    _unacknowledgedMessageMap.visit(new Visitor() {

        @Override
        public boolean callback(final long deliveryTag, final MessageConsumerAssociation messageConsumerPair) {
            copy.put(deliveryTag, messageConsumerPair);
            return false;
        }

        @Override
        public void visitComplete() {
        }
    });
    if (!copy.isEmpty()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Requeuing {} unacked messages", copy.size());
        }
    }
    for (Map.Entry<Long, MessageConsumerAssociation> entry : copy.entrySet()) {
        MessageInstance unacked = entry.getValue().getMessageInstance();
        MessageInstanceConsumer consumer = entry.getValue().getConsumer();
        // Mark message redelivered
        unacked.setRedelivered();
        // here we wish to restore credit
        _unacknowledgedMessageMap.remove(entry.getKey(), true);
        // Ensure message is released for redelivery
        unacked.release(consumer);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) Visitor(org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMap.Visitor) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with MessageInstanceConsumer

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

the class AMQChannel method rollback.

private void rollback(Runnable postRollbackTask) {
    // stop all subscriptions
    _rollingBack = true;
    // TODO This is probably superfluous owing to the
    boolean requiresSuspend = _suspended.compareAndSet(false, true);
    try {
        _transaction.rollback();
    } finally {
        _rollingBack = false;
        _connection.incrementTransactionRollbackCounter();
        _connection.incrementTransactionBeginCounter();
    }
    postRollbackTask.run();
    for (MessageConsumerAssociation association : _resendList) {
        final MessageInstance messageInstance = association.getMessageInstance();
        final MessageInstanceConsumer consumer = association.getConsumer();
        if (consumer.isClosed()) {
            messageInstance.release(consumer);
        } else {
            if (messageInstance.makeAcquisitionUnstealable(consumer) && _creditManager.useCreditForMessage(association.getSize())) {
                consumer.getTarget().send(consumer, messageInstance, false);
            } else {
                messageInstance.release(consumer);
            }
        }
    }
    _resendList.clear();
    if (requiresSuspend) {
        _suspended.set(false);
        for (ConsumerTarget_0_8 target : getConsumerTargets()) {
            for (MessageInstanceConsumer sub : target.getConsumers()) {
                sub.externalStateChange();
            }
        }
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer)

Example 5 with MessageInstanceConsumer

use of org.apache.qpid.server.message.MessageInstanceConsumer 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)

Aggregations

MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)12 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 HashMap (java.util.HashMap)4 Map (java.util.Map)3 MessageContainer (org.apache.qpid.server.message.MessageContainer)3 ServerMessage (org.apache.qpid.server.message.ServerMessage)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ConsumerOption (org.apache.qpid.server.consumer.ConsumerOption)2 ConsumerTarget (org.apache.qpid.server.consumer.ConsumerTarget)2 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)2 MessageSource (org.apache.qpid.server.message.MessageSource)2 Visitor (org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMap.Visitor)2 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1