use of org.apache.qpid.server.store.berkeleydb.entry.QueueEntryKey in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method dequeueMessage.
/**
* Extracts a message from a specified queue, in a given transaction.
*
* @param tx The transaction for the operation.
* @param queueId The id of the queue to take the message from.
* @param messageId The message to dequeue.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
private void dequeueMessage(final Transaction tx, final UUID queueId, long messageId) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
QueueEntryKey queueEntryKey = new QueueEntryKey(queueId, messageId);
UUID id = queueId;
QueueEntryBinding.objectToEntry(queueEntryKey, key);
getLogger().debug("Dequeue message id {} from queue with id {}", messageId, id);
try {
OperationStatus status = getDeliveryDb().delete(tx, key);
if (status == OperationStatus.NOTFOUND) {
throw new StoreException("Unable to find message with id " + messageId + " on queue with id " + id);
} else if (status != OperationStatus.SUCCESS) {
throw new StoreException("Unable to remove message with id " + messageId + " on queue with id " + id);
}
getLogger().debug("Removed message {} on queue with id {}", messageId, id);
} catch (RuntimeException e) {
getLogger().error("Failed to dequeue message " + messageId + " in transaction " + tx, e);
throw getEnvironmentFacade().handleDatabaseException("Error accessing database while dequeuing message: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.berkeleydb.entry.QueueEntryKey in project qpid-broker-j by apache.
the class QueueEntryBinding method entryToObject.
public static QueueEntryKey entryToObject(final CachingUUIDFactory uuidFactory, DatabaseEntry entry) {
byte[] data = entry.getData();
int offset = entry.getOffset();
UUID queueId = uuidFactory.createUuidFromBits(readUnsignedLong(data, offset) ^ 0x8000000000000000L, readUnsignedLong(data, offset + 8) ^ 0x8000000000000000L);
long messageId = readUnsignedLong(data, offset + 16) ^ 0x8000000000000000L;
return new QueueEntryKey(queueId, messageId);
}
use of org.apache.qpid.server.store.berkeleydb.entry.QueueEntryKey in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method enqueueMessage.
/**
* Places a message onto a specified queue, in a given transaction.
*
* @param tx The transaction for the operation.
* @param queue The the queue to place the message on.
* @param messageId The message to enqueue.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason.
*/
private void enqueueMessage(final Transaction tx, final TransactionLogResource queue, long messageId) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
QueueEntryKey queueEntryKey = new QueueEntryKey(queue.getId(), messageId);
QueueEntryBinding.objectToEntry(queueEntryKey, key);
DatabaseEntry value = new DatabaseEntry();
value.setData(ENQUEUE_RECORD_VALUE, 0, ENQUEUE_RECORD_VALUE.length);
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Enqueuing message {} on queue {} with id {} in transaction {}", messageId, queue.getName(), queue.getId(), tx);
}
getDeliveryDb().put(tx, key, value);
} catch (RuntimeException e) {
getLogger().error("Failed to enqueue: {}", e.getMessage(), e);
throw getEnvironmentFacade().handleDatabaseException("Error writing enqueued message with id " + messageId + " for queue " + queue.getName() + " with id " + queue.getId() + " to database", e);
}
}
Aggregations