Search in sources :

Example 1 with MessageMetaDataType

use of org.apache.qpid.server.plugin.MessageMetaDataType in project qpid-broker-j by apache.

the class AbstractJDBCMessageStore method getStorableMessageMetaData.

private StorableMessageMetaData getStorableMessageMetaData(final long messageId, final InputStream stream) throws SQLException {
    try {
        int typeOrdinal = stream.read() & 0xff;
        MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(typeOrdinal);
        try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream)) {
            return type.createMetaData(buf);
        }
    } catch (IOException | RuntimeException e) {
        throw new StoreException("Failed to stream metadata for message with id " + messageId, e);
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) IOException(java.io.IOException) MessageMetaDataType(org.apache.qpid.server.plugin.MessageMetaDataType) StoreException(org.apache.qpid.server.store.StoreException)

Example 2 with MessageMetaDataType

use of org.apache.qpid.server.plugin.MessageMetaDataType in project qpid-broker-j by apache.

the class MessageStoreSerializer_v1 method deserializeMessages.

private Record deserializeMessages(final Map<Long, StoredMessage<?>> messageNumberMap, final MessageStore store, final Deserializer deserializer, Record record) throws IOException {
    while (record.getType() == RecordType.MESSAGE) {
        MessageRecord messageRecord = (MessageRecord) record;
        long originalMessageNumber = messageRecord.getMessageNumber();
        byte[] metaData = messageRecord.getMetaData();
        final MessageMetaDataType metaDataType = MessageMetaDataTypeRegistry.fromOrdinal(metaData[0] & 0xff);
        final MessageHandle<StorableMessageMetaData> handle;
        try (QpidByteBuffer buf = QpidByteBuffer.wrap(metaData, 1, metaData.length - 1)) {
            try {
                StorableMessageMetaData storableMessageMetaData = metaDataType.createMetaData(buf);
                handle = store.addMessage(storableMessageMetaData);
            } catch (ConnectionScopedRuntimeException e) {
                throw new IllegalArgumentException("Could not deserialize message metadata", e);
            }
        }
        try (QpidByteBuffer buf = QpidByteBuffer.wrap(messageRecord.getContent())) {
            handle.addContent(buf);
        }
        final StoredMessage<StorableMessageMetaData> storedMessage = handle.allContentAdded();
        messageNumberMap.put(originalMessageNumber, storedMessage);
        storedMessage.flowToDisk();
        record = deserializer.readRecord();
    }
    return record;
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) MessageMetaDataType(org.apache.qpid.server.plugin.MessageMetaDataType)

Example 3 with MessageMetaDataType

use of org.apache.qpid.server.plugin.MessageMetaDataType in project qpid-broker-j by apache.

the class MessageMetaDataBinding method entryToObject.

@Override
public StorableMessageMetaData entryToObject(DatabaseEntry entry) {
    try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(entry.getData(), entry.getOffset(), entry.getSize()))) {
        final int bodySize = stream.readInt() ^ 0x80000000;
        final int metaDataType = stream.readByte() & 0xff;
        MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(metaDataType);
        try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream)) {
            return type.createMetaData(buf);
        }
    } catch (IOException | RuntimeException e) {
        throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) MessageMetaDataType(org.apache.qpid.server.plugin.MessageMetaDataType) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 MessageMetaDataType (org.apache.qpid.server.plugin.MessageMetaDataType)3 IOException (java.io.IOException)2 StoreException (org.apache.qpid.server.store.StoreException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1