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);
}
}
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;
}
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));
}
}
Aggregations