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;
}
}
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;
}
}
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);
}
}
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();
}
}
}
}
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));
}
Aggregations