use of org.apache.qpid.server.util.ConnectionScopedRuntimeException 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.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class AbstractConsumerTargetTest method testConversionExceptionPolicyWhenOwningResourceIsNotMessageSource.
public void testConversionExceptionPolicyWhenOwningResourceIsNotMessageSource() throws Exception {
final TransactionLogResource owningResource = mock(TransactionLogResource.class);
when(_messageInstance.getOwningResource()).thenReturn(owningResource);
try {
_consumerTarget.sendNextMessage();
fail("exception not thrown");
} catch (ConnectionScopedRuntimeException e) {
assertTrue(String.format("ConnectionScopedRuntimeException has unexpected cause '%s'", e.getCause().getClass().getSimpleName()), e.getCause() instanceof MessageConversionException);
}
assertTrue("message credit was not restored", _consumerTarget.isCreditRestored());
verify(_messageInstance, never()).routeToAlternate(any(Action.class), any(ServerTransaction.class));
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class InternalMessage method createMessage.
public static InternalMessage createMessage(final MessageStore store, final AMQMessageHeader header, final Serializable bodyObject, final boolean persistent, final String destinationName) {
InternalMessageHeader internalHeader;
if (header instanceof InternalMessageHeader) {
internalHeader = (InternalMessageHeader) header;
} else {
internalHeader = new InternalMessageHeader(header);
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
try (ObjectOutputStream os = new ObjectOutputStream(bytesOut)) {
os.writeObject(bodyObject);
os.close();
byte[] bytes = bytesOut.toByteArray();
final InternalMessageMetaData metaData = InternalMessageMetaData.create(persistent, internalHeader, bytes.length);
MessageHandle<InternalMessageMetaData> handle = store.addMessage(metaData);
final StoredMessage<InternalMessageMetaData> storedMessage;
try (QpidByteBuffer wrap = QpidByteBuffer.wrap(bytes)) {
handle.addContent(wrap);
}
storedMessage = handle.allContentAdded();
return new InternalMessage(storedMessage, internalHeader, bodyObject, destinationName);
} catch (IOException e) {
throw new ConnectionScopedRuntimeException("Unexpected IO Exception on operation in memory", e);
}
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class InternalMessageMetaData method ensureHeaderIsEncoded.
private void ensureHeaderIsEncoded() {
if (_headerBytes == null) {
try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bytesOut)) {
os.writeInt(_contentSize);
os.writeObject(_header);
os.close();
_headerBytes = bytesOut.toByteArray();
} catch (IOException e) {
throw new ConnectionScopedRuntimeException("Unexpected IO Exception on in memory operation", e);
}
}
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class InternalMessageMetaDataType method createMetaData.
@Override
public InternalMessageMetaData createMetaData(final QpidByteBuffer buf) {
try (ObjectInputStream is = new ObjectInputStream(buf.asInputStream())) {
int contentSize = is.readInt();
InternalMessageHeader header = (InternalMessageHeader) is.readObject();
return new InternalMessageMetaData(true, header, contentSize);
} catch (IOException e) {
throw new ConnectionScopedRuntimeException("Unexpected IO Exception on operation in memory", e);
} catch (ClassNotFoundException e) {
throw new ConnectionScopedRuntimeException("Unexpected exception when reading meta data, check classpath", e);
}
}
Aggregations