Search in sources :

Example 1 with MessageMetaData

use of org.apache.qpid.server.protocol.v0_8.MessageMetaData in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method convertToStoredMessage.

private StoredMessage<MessageMetaData> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
    final byte[] convertedContent = convertedContentAndMimeType.getContent();
    final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg, convertedContentAndMimeType.getMimeType(), convertedContent.length, addressSpace);
    final int metadataSize = messageMetaData_0_8.getStorableSize();
    return new StoredMessage<MessageMetaData>() {

        @Override
        public MessageMetaData getMetaData() {
            return messageMetaData_0_8;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(convertedContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return convertedContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInMemory() {
            return true;
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) StoredMessage(org.apache.qpid.server.store.StoredMessage) ConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType) MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)

Example 2 with MessageMetaData

use of org.apache.qpid.server.protocol.v0_8.MessageMetaData in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final Message_1_0 serverMsg, final String bodyMimeType, final int size, final NamedAddressSpace addressSpace) {
    final MessageMetaData_1_0.MessageHeader_1_0 header = serverMsg.getMessageHeader();
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setEncoding(convertToShortStringForProperty("content-encoding", serverMsg.getMessageHeader().getEncoding()));
    props.setCorrelationId(getCorrelationIdAsShortString(serverMsg));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    final Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
    if (absoluteExpiryTime != null) {
        props.setExpiration(absoluteExpiryTime.getTime());
    } else {
        Long ttl = getTtl(serverMsg);
        if (ttl != null) {
            props.setExpiration(ttl + serverMsg.getArrivalTime());
        }
    }
    props.setMessageId(getMessageIdAsShortString(serverMsg));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(getReplyTo(serverMsg, addressSpace));
    Date timestamp = getCreationTime(serverMsg);
    if (timestamp != null) {
        props.setTimestamp(timestamp.getTime());
    } else {
        props.setTimestamp(serverMsg.getArrivalTime());
    }
    props.setUserId(getUserIdAsShortString(serverMsg));
    Map<String, Object> headerProps = new LinkedHashMap<>();
    if (header.getSubject() != null) {
        headerProps.put("qpid.subject", header.getSubject());
        props.setType(convertToShortStringForProperty("subject", header.getSubject()));
    }
    String groupId = getGroupId(serverMsg);
    if (groupId != null) {
        headerProps.put("JMSXGroupID", groupId);
    }
    UnsignedInteger groupSequence = getGroupSequence(serverMsg);
    if (groupSequence != null) {
        headerProps.put("JMSXGroupSeq", groupSequence.intValue());
    }
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, convertValue(serverMsg.getMessageHeader().getHeader(headerName)));
    }
    final FieldTable headers;
    try {
        headers = FieldTable.convertToFieldTable(headerProps);
    } catch (IllegalArgumentException e) {
        throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'application-properties' failed.", e);
    }
    props.setHeaders(headers);
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    MessagePublishInfo publishInfo = createMessagePublishInfo(header, addressSpace);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 3 with MessageMetaData

use of org.apache.qpid.server.protocol.v0_8.MessageMetaData in project qpid-broker-j by apache.

the class BDBMessageStoreTest method createAndStoreSingleChunkMessage_0_8.

private StoredMessage<MessageMetaData> createAndStoreSingleChunkMessage_0_8(MessageStore store) {
    QpidByteBuffer chunk1 = QpidByteBuffer.wrap(CONTENT_BYTES);
    int bodySize = CONTENT_BYTES.length;
    // create and store the message using the MessageStore interface
    MessagePublishInfo pubInfoBody_0_8 = createPublishInfoBody_0_8();
    BasicContentHeaderProperties props_0_8 = createContentHeaderProperties_0_8();
    ContentHeaderBody chb_0_8 = createContentHeaderBody_0_8(props_0_8, bodySize);
    MessageMetaData messageMetaData_0_8 = new MessageMetaData(pubInfoBody_0_8, chb_0_8);
    MessageHandle<MessageMetaData> storedMessage_0_8 = store.addMessage(messageMetaData_0_8);
    storedMessage_0_8.addContent(chunk1);
    ((AbstractBDBMessageStore.StoredBDBMessage) storedMessage_0_8).flushToStore();
    return storedMessage_0_8.allContentAdded();
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 4 with MessageMetaData

use of org.apache.qpid.server.protocol.v0_8.MessageMetaData in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    MessagePublishInfo publishInfo = createMessagePublishInfo(serverMsg, addressSpace);
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setCorrelationId(convertToShortStringForProperty("correlation-id", serverMsg.getMessageHeader().getCorrelationId()));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    props.setExpiration(serverMsg.getExpiration());
    props.setMessageId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getMessageId()));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(convertToShortStringForProperty("reply-to", getReplyTo(serverMsg, addressSpace)));
    props.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
    props.setUserId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getUserId()));
    props.setEncoding(convertToShortStringForProperty("encoding", serverMsg.getMessageHeader().getEncoding()));
    Map<String, Object> headerProps = new LinkedHashMap<String, Object>();
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, serverMsg.getMessageHeader().getHeader(headerName));
    }
    try {
        props.setHeaders(FieldTable.convertToFieldTable(headerProps));
    } catch (IllegalArgumentException | AMQPInvalidClassException e) {
        throw new MessageConversionException("Could not convert message from internal to 0-8 because headers conversion failed.", e);
    }
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with MessageMetaData

use of org.apache.qpid.server.protocol.v0_8.MessageMetaData in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method createMessage.

@Override
public AMQMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    try {
        AMQShortString exchange = readShortString(payload);
        AMQShortString routingKey = readShortString(payload);
        byte flags = payload.get();
        final MessagePublishInfo publishBody = new MessagePublishInfo(exchange, (flags & IMMEDIATE_MASK) != 0, (flags & MANDATORY_MASK) != 0, routingKey);
        final ContentHeaderBody contentHeaderBody = readContentBody(payload);
        MessageMetaData mmd = new MessageMetaData(publishBody, contentHeaderBody);
        final MessageHandle<MessageMetaData> handle = store.addMessage(mmd);
        handle.addContent(payload);
        final StoredMessage<MessageMetaData> storedMessage = handle.allContentAdded();
        return new AMQMessage(storedMessage, connectionReference);
    } catch (AMQFrameDecodingException | BufferUnderflowException e) {
        throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-9-1 message format", e);
    }
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)10 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)10 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)6 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)4 StoredMessage (org.apache.qpid.server.store.StoredMessage)4 LinkedHashMap (java.util.LinkedHashMap)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)2 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)2 Transaction (org.apache.qpid.server.store.Transaction)2 BufferUnderflowException (java.nio.BufferUnderflowException)1 Date (java.util.Date)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)1 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)1 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)1 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)1 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)1 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1