Search in sources :

Example 11 with EnqueueableMessage

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

the class SynchronousMessageStoreRecovererTest method createMockEnqueueableMessage.

protected EnqueueableMessage createMockEnqueueableMessage(long messageId, final StoredMessage<StorableMessageMetaData> storedMessage) {
    EnqueueableMessage enqueueableMessage = mock(EnqueueableMessage.class);
    when(enqueueableMessage.getMessageNumber()).thenReturn(messageId);
    when(enqueueableMessage.getStoredMessage()).thenReturn(storedMessage);
    return enqueueableMessage;
}
Also used : EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage)

Example 12 with EnqueueableMessage

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

the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleEnqueueWithDistributedTransaction.

@SuppressWarnings("unchecked")
public void testRecoveryOfSingleEnqueueWithDistributedTransaction() {
    Queue<?> queue = createRegisteredMockQueue();
    final Transaction transaction = mock(Transaction.class);
    final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(1);
    long messageId = storedMessage.getMessageNumber();
    EnqueueableMessage enqueueableMessage = createMockEnqueueableMessage(messageId, storedMessage);
    EnqueueRecord enqueueRecord = createMockRecord(queue, enqueueableMessage);
    final long format = 1;
    final byte[] globalId = new byte[] { 0 };
    final byte[] branchId = new byte[] { 0 };
    final EnqueueRecord[] enqueues = { enqueueRecord };
    final Transaction.DequeueRecord[] dequeues = {};
    MessageStore store = new NullMessageStore() {

        @Override
        public void visitMessages(MessageHandler handler) throws StoreException {
            handler.handle(storedMessage);
        }

        @Override
        public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
        // No messages instances
        }

        @Override
        public void visitDistributedTransactions(DistributedTransactionHandler handler) throws StoreException {
            handler.handle(new Transaction.StoredXidRecord() {

                @Override
                public long getFormat() {
                    return format;
                }

                @Override
                public byte[] getGlobalId() {
                    return globalId;
                }

                @Override
                public byte[] getBranchId() {
                    return branchId;
                }
            }, enqueues, dequeues);
        }

        @Override
        public Transaction newTransaction() {
            return transaction;
        }
    };
    DtxRegistry dtxRegistry = new DtxRegistry(_virtualHost);
    when(_virtualHost.getMessageStore()).thenReturn(store);
    when(_virtualHost.getDtxRegistry()).thenReturn(dtxRegistry);
    SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
    recoverer.recover(_virtualHost);
    DtxBranch branch = dtxRegistry.getBranch(new Xid(format, globalId, branchId));
    assertNotNull("Expected dtx branch to be created", branch);
    branch.commit();
    ServerMessage<?> message = storedMessage.getMetaData().getType().createMessage(storedMessage);
    verify(queue, times(1)).enqueue(eq(message), (Action<? super MessageInstance>) isNull(), any(MessageEnqueueRecord.class));
    verify(transaction).commitTran();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) DistributedTransactionHandler(org.apache.qpid.server.store.handler.DistributedTransactionHandler) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) EnqueueRecord(org.apache.qpid.server.store.Transaction.EnqueueRecord) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Xid(org.apache.qpid.server.txn.Xid) Transaction(org.apache.qpid.server.store.Transaction) DtxRegistry(org.apache.qpid.server.txn.DtxRegistry) EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) DtxBranch(org.apache.qpid.server.txn.DtxBranch)

Example 13 with EnqueueableMessage

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

the class MessageStoreSerializer_v1 method deserializeMessageInstances.

private Record deserializeMessageInstances(final MessageStore store, final Map<UUID, UUID> queueIdMap, final Map<Long, StoredMessage<?>> messageMap, final Deserializer deserializer, Record nextRecord) throws IOException {
    while (nextRecord.getType() == RecordType.MESSAGE_INSTANCE) {
        MessageInstanceRecord messageInstanceRecord = (MessageInstanceRecord) nextRecord;
        final StoredMessage<?> storedMessage = messageMap.get(messageInstanceRecord.getMessageNumber());
        final UUID queueId = queueIdMap.get(messageInstanceRecord.getQueueId());
        if (storedMessage != null && queueId != null) {
            final Transaction txn = store.newTransaction();
            EnqueueableMessage msg = new EnqueueableMessage() {

                @Override
                public long getMessageNumber() {
                    return storedMessage.getMessageNumber();
                }

                @Override
                public boolean isPersistent() {
                    return true;
                }

                @Override
                public StoredMessage getStoredMessage() {
                    return storedMessage;
                }
            };
            txn.enqueueMessage(new TransactionLogResource() {

                @Override
                public String getName() {
                    return queueId.toString();
                }

                @Override
                public UUID getId() {
                    return queueId;
                }

                @Override
                public MessageDurability getMessageDurability() {
                    return MessageDurability.DEFAULT;
                }
            }, msg);
            txn.commitTranAsync(null);
        }
        nextRecord = deserializer.readRecord();
    }
    return nextRecord;
}
Also used : MessageDurability(org.apache.qpid.server.store.MessageDurability) Transaction(org.apache.qpid.server.store.Transaction) EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) UUID(java.util.UUID) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Aggregations

EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)13 UUID (java.util.UUID)7 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)2 Transaction (org.apache.qpid.server.store.Transaction)2 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)2 ArrayList (java.util.ArrayList)1 MessageDurability (org.apache.qpid.server.store.MessageDurability)1 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)1 MessageStore (org.apache.qpid.server.store.MessageStore)1 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)1 StoredMessage (org.apache.qpid.server.store.StoredMessage)1 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)1 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)1 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)1 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)1 DtxBranch (org.apache.qpid.server.txn.DtxBranch)1 DtxRegistry (org.apache.qpid.server.txn.DtxRegistry)1 Xid (org.apache.qpid.server.txn.Xid)1