Search in sources :

Example 1 with ConnectionScopedRuntimeException

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;
}
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 2 with ConnectionScopedRuntimeException

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));
}
Also used : Action(org.apache.qpid.server.util.Action) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 3 with ConnectionScopedRuntimeException

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);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 4 with ConnectionScopedRuntimeException

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);
        }
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 5 with ConnectionScopedRuntimeException

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);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)32 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)9 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)6 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)3 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2 ObjectOutputStream (java.io.ObjectOutputStream)2 BufferUnderflowException (java.nio.BufferUnderflowException)2