use of com.sleepycat.je.OperationStatus 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) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Failed to dequeue message {} in transaction {}", messageId, tx, e);
}
throw getEnvironmentFacade().handleDatabaseException("Error accessing database while dequeuing message: " + e.getMessage(), e);
}
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method getMessageData.
/**
* @return a (sorted) map of offset -> data for the given message id
*/
private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase) {
TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>();
Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED);
try {
DatabaseEntry contentKeyEntry = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
CompoundKeyBinding binding = new CompoundKeyBinding();
binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry);
OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT);
OldDataBinding dataBinding = new OldDataBinding();
while (status == OperationStatus.SUCCESS) {
CompoundKey compoundKey = binding.entryToObject(contentKeyEntry);
long id = compoundKey.getMessageId();
if (id != messageId) {
// we have exhausted all chunks for this message id, break
break;
}
int offsetInMessage = compoundKey.getOffset();
OldDataValue dataValue = dataBinding.entryToObject(value);
data.put(offsetInMessage, dataValue.getData());
status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT);
}
} finally {
cursor.close();
}
return data;
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method getTestKeyValue.
private String getTestKeyValue(final Database db, final int keyValue) {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry result = new DatabaseEntry();
IntegerBinding.intToEntry(keyValue, key);
final OperationStatus status = db.get(null, key, result, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
return StringBinding.entryToString(result);
}
return null;
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class UpgradeFrom7To8 method storeConfiguredObjectEntry.
private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject) {
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
uuidBinding.objectToEntry(configuredObject.getId(), key);
DatabaseEntry value = new DatabaseEntry();
ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
configuredObjectBinding.objectToEntry(configuredObject, value);
OperationStatus status = configuredObjectsDb.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
}
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class BDBConfigurationStore method writeHierarchyRecords.
private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject) {
OperationStatus status;
HierarchyKeyBinding hierarchyBinding = HierarchyKeyBinding.getInstance();
DatabaseEntry hierarchyKey = new DatabaseEntry();
DatabaseEntry hierarchyValue = new DatabaseEntry();
for (Map.Entry<String, UUID> parent : configuredObject.getParents().entrySet()) {
hierarchyBinding.objectToEntry(new HierarchyKey(configuredObject.getId(), parent.getKey()), hierarchyKey);
UUIDTupleBinding.getInstance().objectToEntry(parent.getValue(), hierarchyValue);
status = getConfiguredObjectHierarchyDb().put(txn, hierarchyKey, hierarchyValue);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " parent record to database: " + status);
}
}
}
Aggregations