Search in sources :

Example 1 with MessageMetaDataBinding

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);
    }
}
Also used : MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 2 with MessageMetaDataBinding

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);
    }
}
Also used : MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 3 with MessageMetaDataBinding

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);
    }
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) StoreException(org.apache.qpid.server.store.StoreException)

Example 4 with MessageMetaDataBinding

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);
    }
}
Also used : MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 5 with MessageMetaDataBinding

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;
}
Also used : MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 MessageMetaDataBinding (org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding)5 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)3 Cursor (com.sleepycat.je.Cursor)2 OperationStatus (com.sleepycat.je.OperationStatus)1 StoreException (org.apache.qpid.server.store.StoreException)1