use of org.apache.qpid.server.store.TransactionLogResource in project qpid-broker-j by apache.
the class JDBCMessageStoreTest method testDequeueTransactionCommitAsync.
public void testDequeueTransactionCommitAsync() throws Exception {
final String queueName = getTestName();
final UUID transactionalLogId = UUID.randomUUID();
final MessageStore store = getStore();
final TransactionLogResource transactionalLog = mockTransactionLogResource(transactionalLogId, queueName);
final InternalMessage message = addTestMessage(store, queueName, "test2");
final Transaction enqueueTransaction = store.newTransaction();
MessageEnqueueRecord record = enqueueTransaction.enqueueMessage(transactionalLog, message);
enqueueTransaction.commitTran();
final Transaction dequeueTransaction = store.newTransaction();
dequeueTransaction.dequeueMessage(record);
final ListenableFuture<Void> future = dequeueTransaction.commitTranAsync(null);
future.get(1000, TimeUnit.MILLISECONDS);
}
use of org.apache.qpid.server.store.TransactionLogResource in project qpid-broker-j by apache.
the class AMQChannel method deadLetter.
private void deadLetter(long deliveryTag) {
final UnacknowledgedMessageMap unackedMap = getUnacknowledgedMessageMap();
final MessageConsumerAssociation association = unackedMap.remove(deliveryTag, true);
if (association == null) {
LOGGER.warn("No message found, unable to DLQ delivery tag: " + deliveryTag);
} else {
final MessageInstance messageInstance = association.getMessageInstance();
final ServerMessage msg = messageInstance.getMessage();
int requeues = 0;
if (messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
requeues = messageInstance.routeToAlternate(new Action<MessageInstance>() {
@Override
public void performAction(final MessageInstance requeueEntry) {
messageWithSubject(ChannelMessages.DEADLETTERMSG(msg.getMessageNumber(), requeueEntry.getOwningResource().getName()));
}
}, null);
}
if (requeues == 0) {
final TransactionLogResource owningResource = messageInstance.getOwningResource();
if (owningResource instanceof Queue) {
final Queue<?> queue = (Queue<?>) owningResource;
final MessageDestination alternateBindingDestination = queue.getAlternateBindingDestination();
if (alternateBindingDestination == null) {
messageWithSubject(ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getInitialRoutingAddress()));
} else {
messageWithSubject(ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateBindingDestination.getName()));
}
}
}
}
}
use of org.apache.qpid.server.store.TransactionLogResource 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;
}
}
use of org.apache.qpid.server.store.TransactionLogResource in project qpid-broker-j by apache.
the class AbstractServerMessageTest method testReferences.
public void testReferences() {
TransactionLogResource q1 = createQueue("1");
TransactionLogResource q2 = createQueue("2");
TestMessage<StorableMessageMetaData> msg = new TestMessage<StorableMessageMetaData>(mock(StoredMessage.class), this);
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
MessageReference<TestMessage<StorableMessageMetaData>> nonQueueRef = msg.newReference();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
MessageReference<TestMessage<StorableMessageMetaData>> q1ref = msg.newReference(q1);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
q1ref.release();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
q1ref = msg.newReference(q1);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
MessageReference<TestMessage<StorableMessageMetaData>> q2ref = msg.newReference(q2);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertTrue(msg.isReferenced(q2));
try {
msg.newReference(q1);
fail("Should not be able to create a second reference to the same queue");
} catch (MessageAlreadyReferencedException e) {
// pass
}
q2ref.release();
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
q1ref.release();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
nonQueueRef.release();
try {
msg.newReference(q1);
fail("Message should not allow new references as all references had been removed");
} catch (MessageDeletedException e) {
// pass
}
}
use of org.apache.qpid.server.store.TransactionLogResource in project qpid-broker-j by apache.
the class LocalTransactionTest method createTestQueueEntries.
private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
for (int i = 0; i < queueDurableFlags.length; i++) {
final TransactionLogResource queue = createQueue(queueDurableFlags[i]);
final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
queueEntries.add(new MockMessageInstance() {
@Override
public ServerMessage getMessage() {
return message;
}
@Override
public TransactionLogResource getOwningResource() {
return queue;
}
@Override
public MessageEnqueueRecord getEnqueueRecord() {
return hasRecord ? mock(MessageEnqueueRecord.class) : null;
}
});
}
return queueEntries;
}
Aggregations