Search in sources :

Example 6 with TransactionLogResource

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);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 7 with TransactionLogResource

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()));
                }
            }
        }
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) PrivilegedAction(java.security.PrivilegedAction) Action(org.apache.qpid.server.util.Action) MessageDestination(org.apache.qpid.server.message.MessageDestination) ServerMessage(org.apache.qpid.server.message.ServerMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Example 8 with TransactionLogResource

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

Example 9 with TransactionLogResource

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
    }
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 10 with TransactionLogResource

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;
}
Also used : MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) MessageInstance(org.apache.qpid.server.message.MessageInstance) MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) ArrayList(java.util.ArrayList) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Aggregations

TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)12 MessageInstance (org.apache.qpid.server.message.MessageInstance)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)4 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 UUID (java.util.UUID)3 Transaction (org.apache.qpid.server.store.Transaction)3 Action (org.apache.qpid.server.util.Action)3 ArrayList (java.util.ArrayList)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)2 Queue (org.apache.qpid.server.model.Queue)2 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)2 MockMessageInstance (org.apache.qpid.server.queue.MockMessageInstance)2 MessageStore (org.apache.qpid.server.store.MessageStore)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 PrivilegedAction (java.security.PrivilegedAction)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)1 MessageContainer (org.apache.qpid.server.message.MessageContainer)1 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)1