Search in sources :

Example 11 with StorableMessageMetaData

use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.

the class AbstractBDBMessageStore method getMessageInternal.

private StoredBDBMessage<?> getMessageInternal(long messageId, EnvironmentFacade environmentFacade) {
    try {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
        LongBinding.longToEntry(messageId, key);
        if (getMessageMetaDataDb().get(null, key, value, LockMode.READ_COMMITTED) == OperationStatus.SUCCESS) {
            StorableMessageMetaData metaData = valueBinding.entryToObject(value);
            StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
            return message;
        } else {
            return null;
        }
    } catch (RuntimeException e) {
        throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
    }
}
Also used : MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 12 with StorableMessageMetaData

use of org.apache.qpid.server.store.StorableMessageMetaData 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 13 with StorableMessageMetaData

use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.

the class AsynchronousMessageStoreRecovererTest method createTestMessage.

private StoredMessage<?> createTestMessage(final long messageNumber) {
    final StorableMessageMetaData metaData = new TestMessageMetaData(messageNumber, 0);
    final StoredMessage storedMessage = mock(StoredMessage.class);
    when(storedMessage.getMessageNumber()).thenReturn(messageNumber);
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return storedMessage;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) TestMessageMetaData(org.apache.qpid.server.store.TestMessageMetaData) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 14 with StorableMessageMetaData

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

Aggregations

StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)14 MessageStore (org.apache.qpid.server.store.MessageStore)5 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)5 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)5 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)5 DatabaseEntry (com.sleepycat.je.DatabaseEntry)4 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)3 StoredMessage (org.apache.qpid.server.store.StoredMessage)3 Transaction (org.apache.qpid.server.store.Transaction)3 MessageMetaDataBinding (org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding)3 UUID (java.util.UUID)2 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)2 TestMessageMetaData (org.apache.qpid.server.store.TestMessageMetaData)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)2 DtxBranch (org.apache.qpid.server.txn.DtxBranch)2 DtxRegistry (org.apache.qpid.server.txn.DtxRegistry)2 Xid (org.apache.qpid.server.txn.Xid)2 Cursor (com.sleepycat.je.Cursor)1 Database (com.sleepycat.je.Database)1