use of org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding 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);
try {
getMessageMetaDataDb().put(tx, key, value);
getLogger().debug("Storing message metadata for message id {} in transaction {}", messageId, tx);
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error writing message metadata with id " + messageId + " to database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding 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 org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method getMessageMetaData.
/**
* Retrieves message meta-data.
*
* @param messageId The message to get the meta-data for.
*
* @return The message meta data.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
StorableMessageMetaData getMessageMetaData(long messageId) throws StoreException {
getLogger().debug("public MessageMetaData getMessageMetaData(Long messageId = {}): called", messageId);
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding messageBinding = MessageMetaDataBinding.getInstance();
try {
OperationStatus status = getMessageMetaDataDb().get(null, key, value, LockMode.READ_UNCOMMITTED);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Metadata not found for message with id " + messageId);
}
StorableMessageMetaData mdd = messageBinding.entryToObject(value);
return mdd;
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error reading message metadata for message with id " + messageId + ": " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method getMessageInternal.
private StoredBDBMessage<?> getMessageInternal(long messageId, EnvironmentFacade environmentFacade) {
try {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
LongBinding.longToEntry(messageId, key);
if (getMessageMetaDataDb().get(null, key, value, LockMode.READ_COMMITTED) == OperationStatus.SUCCESS) {
StorableMessageMetaData metaData = valueBinding.entryToObject(value);
StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
return message;
} else {
return null;
}
} catch (RuntimeException e) {
throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding in project qpid-broker-j by apache.
the class UpgradeFrom7To8 method getMaximumMessageId.
private long getMaximumMessageId(Database messageMetaDataDb) {
Cursor cursor = null;
// Our hand-rolled sequences value always began at zero
long maximumMessageId = 0;
try {
cursor = messageMetaDataDb.openCursor(null, null);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) {
long messageId = LongBinding.entryToLong(key);
maximumMessageId = Math.max(messageId, maximumMessageId);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return maximumMessageId;
}
Aggregations