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;
}
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);
}
}
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());
}
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());
}
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() {
}
};
}
Aggregations