Search in sources :

Example 11 with StoredMessage

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

the class FlowToDiskOverflowPolicyHandlerTest method createMessage.

private ServerMessage createMessage(long size) {
    ServerMessage message = mock(ServerMessage.class);
    when(message.getSizeIncludingHeader()).thenReturn(size);
    StoredMessage storedMessage = mock(StoredMessage.class);
    when(message.getStoredMessage()).thenReturn(storedMessage);
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    return message;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 12 with StoredMessage

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

the class AbstractJDBCMessageStore method recordXid.

private List<Runnable> recordXid(ConnectionWrapper connWrapper, long format, byte[] globalId, byte[] branchId, Transaction.EnqueueRecord[] enqueues, Transaction.DequeueRecord[] dequeues) throws StoreException {
    Connection conn = connWrapper.getConnection();
    try {
        try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getXidTableName() + " ( format, global_id, branch_id ) values (?, ?, ?)")) {
            stmt.setLong(1, format);
            stmt.setBytes(2, globalId);
            stmt.setBytes(3, branchId);
            stmt.executeUpdate();
        }
        for (Transaction.EnqueueRecord enqueue : enqueues) {
            StoredMessage storedMessage = enqueue.getMessage().getStoredMessage();
            if (storedMessage instanceof StoredJDBCMessage) {
                ((StoredJDBCMessage) storedMessage).store(conn);
            }
        }
        try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getXidActionsTableName() + " ( format, global_id, branch_id, action_type, " + "queue_id, message_id ) values (?,?,?,?,?,?) ")) {
            stmt.setLong(1, format);
            stmt.setBytes(2, globalId);
            stmt.setBytes(3, branchId);
            if (enqueues != null) {
                stmt.setString(4, "E");
                for (Transaction.EnqueueRecord record : enqueues) {
                    stmt.setString(5, record.getResource().getId().toString());
                    stmt.setLong(6, record.getMessage().getMessageNumber());
                    stmt.executeUpdate();
                }
            }
            if (dequeues != null) {
                stmt.setString(4, "D");
                for (Transaction.DequeueRecord record : dequeues) {
                    stmt.setString(5, record.getEnqueueRecord().getQueueId().toString());
                    stmt.setLong(6, record.getEnqueueRecord().getMessageNumber());
                    stmt.executeUpdate();
                }
            }
        }
        return Collections.emptyList();
    } catch (SQLException e) {
        getLogger().error("Failed to record xid", e);
        throw new StoreException("Error writing xid ", e);
    }
}
Also used : Transaction(org.apache.qpid.server.store.Transaction) StoredMessage(org.apache.qpid.server.store.StoredMessage) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Example 13 with StoredMessage

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

the class ReferenceCountingTest method testMessageGetsRemoved.

/**
 * Check that when the reference count is decremented the message removes itself from the store
 */
public void testMessageGetsRemoved() throws QpidException {
    ContentHeaderBody chb = createPersistentContentHeader();
    MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
    final MessageMetaData mmd = new MessageMetaData(info, chb);
    StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
    Transaction txn = _store.newTransaction();
    txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
    txn.commitTran();
    AMQMessage message = new AMQMessage(storedMessage);
    MessageReference ref = message.newReference();
    assertEquals(1, getStoreMessageCount());
    ref.release();
    assertEquals(0, getStoreMessageCount());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) StoredMessage(org.apache.qpid.server.store.StoredMessage) Transaction(org.apache.qpid.server.store.Transaction) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 14 with StoredMessage

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

the class ReferenceCountingTest method testMessageRemains.

public void testMessageRemains() throws QpidException {
    MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
    final ContentHeaderBody chb = createPersistentContentHeader();
    final MessageMetaData mmd = new MessageMetaData(info, chb);
    StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
    Transaction txn = _store.newTransaction();
    txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
    txn.commitTran();
    AMQMessage message = new AMQMessage(storedMessage);
    MessageReference ref = message.newReference();
    assertEquals(1, getStoreMessageCount());
    MessageReference ref2 = message.newReference();
    ref.release();
    assertEquals(1, getStoreMessageCount());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) StoredMessage(org.apache.qpid.server.store.StoredMessage) Transaction(org.apache.qpid.server.store.Transaction) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 15 with StoredMessage

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

the class MessageConverter_0_10_to_0_8 method convertToStoredMessage.

private StoredMessage<MessageMetaData> convertToStoredMessage(final MessageTransferMessage message, NamedAddressSpace addressSpace) {
    final MessageMetaData metaData = convertMetaData(message, addressSpace);
    final int metadataSize = metaData.getStorableSize();
    return new StoredMessage<org.apache.qpid.server.protocol.v0_8.MessageMetaData>() {

        @Override
        public MessageMetaData getMetaData() {
            return metaData;
        }

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

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return message.getContent(offset, length);
        }

        @Override
        public int getContentSize() {
            return metaData.getContentSize();
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

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

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) StoredMessage(org.apache.qpid.server.store.StoredMessage)

Aggregations

StoredMessage (org.apache.qpid.server.store.StoredMessage)23 MessageReference (org.apache.qpid.server.message.MessageReference)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)4 Transaction (org.apache.qpid.server.store.Transaction)4 UUID (java.util.UUID)3 LogMessage (org.apache.qpid.server.logging.LogMessage)3 HashMap (java.util.HashMap)2 ObjectToMimeContentConverter (org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter)2 Queue (org.apache.qpid.server.model.Queue)2 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)2 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)2 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)2 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)2 MessageStore (org.apache.qpid.server.store.MessageStore)2 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)2 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1