use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method visitMessagesInternal.
private void visitMessagesInternal(MessageHandler handler, EnvironmentFacade environmentFacade) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
try (Cursor cursor = getMessageMetaDataDb().openCursor(null, null)) {
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
long messageId = LongBinding.entryToLong(key);
StorableMessageMetaData metaData = valueBinding.entryToObject(value);
StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
if (!handler.handle(message)) {
break;
}
}
} catch (RuntimeException e) {
throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
}
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method addContent.
/**
* Stores a chunk of message data.
*
* @param tx The transaction for the operation.
* @param messageId The message to store the data for.
* @param contentBody The content of the data chunk.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
private void addContent(final Transaction tx, long messageId, QpidByteBuffer contentBody) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
DatabaseEntry value = new DatabaseEntry();
byte[] data = new byte[contentBody.remaining()];
contentBody.copyTo(data);
value.setData(data);
try {
OperationStatus status = getMessageContentDb().put(tx, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error adding content for message id " + messageId + ": " + status);
}
getLogger().debug("Storing content for message {} in transaction {}", messageId, tx);
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error writing AMQMessage with id " + messageId + " to database: " + e.getMessage(), e);
}
}
use of com.sleepycat.je.DatabaseEntry 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.DatabaseEntry in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method storeMetaData.
/**
* Stores message meta-data.
*
* @param tx The transaction for the operation.
* @param messageId The message to store the data for.
* @param messageMetaData The message meta data to store.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
private void storeMetaData(final Transaction tx, long messageId, StorableMessageMetaData messageMetaData) throws StoreException {
getLogger().debug("storeMetaData called for transaction {}, messageId {}, messageMetaData {} ", tx, messageId, messageMetaData);
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding messageBinding = MessageMetaDataBinding.getInstance();
messageBinding.objectToEntry(messageMetaData, value);
boolean complete = false;
int attempts = 0;
do {
try {
getMessageMetaDataDb().put(tx, key, value);
getLogger().debug("Storing message metadata for message id {} in transaction {}", messageId, tx);
complete = true;
} catch (LockConflictException e) {
sleepOrThrowOnLockConflict(attempts++, "Cannot store metadata", e);
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error writing message metadata with id " + messageId + " to database: " + e.getMessage(), e);
}
} while (!complete);
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeExchanges.
private List<String> upgradeExchanges(Environment environment, Transaction transaction, final String virtualHostName) {
final List<String> exchangeNames = new ArrayList<String>();
LOGGER.info("Exchanges");
if (environment.getDatabaseNames().contains(OLD_EXCHANGE_DB_NAME)) {
final ExchangeBinding exchangeBinding = new ExchangeBinding();
CursorOperation exchangeCursor = new CursorOperation() {
@Override
public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
ExchangeRecord exchangeRecord = exchangeBinding.entryToObject(value);
String exchangeName = exchangeRecord.getNameShortString().toString();
if (!DEFAULT_EXCHANGES_SET.contains(exchangeName) && !"<<default>>".equals(exchangeName)) {
String exchangeType = exchangeRecord.getType().toString();
boolean autoDelete = exchangeRecord.isAutoDelete();
UUID exchangeId = UUIDGenerator.generateExchangeUUID(exchangeName, virtualHostName);
UpgradeConfiguredObjectRecord configuredObject = createExchangeConfiguredObjectRecord(exchangeName, exchangeType, autoDelete);
storeConfiguredObjectEntry(configuredObjectsDatabase, exchangeId, configuredObject, transaction);
exchangeNames.add(exchangeName);
}
}
};
new DatabaseTemplate(environment, OLD_EXCHANGE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(exchangeCursor);
environment.removeDatabase(transaction, OLD_EXCHANGE_DB_NAME);
LOGGER.info(exchangeCursor.getRowCount() + " Exchange Entries");
}
return exchangeNames;
}
Aggregations