Search in sources :

Example 1 with DataStructure

use of org.apache.activemq.command.DataStructure in project activemq-artemis by apache.

the class OpenWireMessageConverter method inbound.

public static org.apache.activemq.artemis.api.core.Message inbound(final Message messageSend, final WireFormat marshaller, final CoreMessageObjectPools coreMessageObjectPools) throws Exception {
    final CoreMessage coreMessage = new CoreMessage(-1, messageSend.getSize(), coreMessageObjectPools);
    final String type = messageSend.getType();
    if (type != null) {
        coreMessage.putStringProperty(JMS_TYPE_PROPERTY, new SimpleString(type));
    }
    coreMessage.setDurable(messageSend.isPersistent());
    coreMessage.setExpiration(messageSend.getExpiration());
    coreMessage.setPriority(messageSend.getPriority());
    coreMessage.setTimestamp(messageSend.getTimestamp());
    final byte coreType = toCoreType(messageSend.getDataStructureType());
    coreMessage.setType(coreType);
    final ActiveMQBuffer body = coreMessage.getBodyBuffer();
    final ByteSequence contents = messageSend.getContent();
    if (contents == null && coreType == org.apache.activemq.artemis.api.core.Message.TEXT_TYPE) {
        body.writeNullableString(null);
    } else if (contents != null) {
        final boolean messageCompressed = messageSend.isCompressed();
        if (messageCompressed) {
            coreMessage.putBooleanProperty(AMQ_MSG_COMPRESSED, messageCompressed);
        }
        switch(coreType) {
            case org.apache.activemq.artemis.api.core.Message.TEXT_TYPE:
                writeTextType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.MAP_TYPE:
                writeMapType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE:
                writeObjectType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.STREAM_TYPE:
                writeStreamType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
                writeBytesType(contents, messageCompressed, body);
                break;
            default:
                writeDefaultType(contents, messageCompressed, body);
                break;
        }
    }
    // amq specific
    coreMessage.putLongProperty(AMQ_MSG_ARRIVAL, messageSend.getArrival());
    coreMessage.putLongProperty(AMQ_MSG_BROKER_IN_TIME, messageSend.getBrokerInTime());
    final BrokerId[] brokers = messageSend.getBrokerPath();
    if (brokers != null) {
        putMsgBrokerPath(brokers, coreMessage);
    }
    final BrokerId[] cluster = messageSend.getCluster();
    if (cluster != null) {
        putMsgCluster(cluster, coreMessage);
    }
    coreMessage.putIntProperty(AMQ_MSG_COMMAND_ID, messageSend.getCommandId());
    final String corrId = messageSend.getCorrelationId();
    if (corrId != null) {
        coreMessage.putStringProperty(JMS_CORRELATION_ID_PROPERTY, new SimpleString(corrId));
    }
    final DataStructure ds = messageSend.getDataStructure();
    if (ds != null) {
        putMsgDataStructure(ds, marshaller, coreMessage);
    }
    final String groupId = messageSend.getGroupID();
    if (groupId != null) {
        coreMessage.putStringProperty(AMQ_MSG_GROUP_ID, coreMessageObjectPools.getGroupIdStringSimpleStringPool().getOrCreate(groupId));
    }
    coreMessage.putIntProperty(AMQ_MSG_GROUP_SEQUENCE, messageSend.getGroupSequence());
    final MessageId messageId = messageSend.getMessageId();
    final ByteSequence midBytes = marshaller.marshal(messageId);
    midBytes.compact();
    coreMessage.putBytesProperty(AMQ_MSG_MESSAGE_ID, midBytes.data);
    final ProducerId producerId = messageSend.getProducerId();
    if (producerId != null) {
        final ByteSequence producerIdBytes = marshaller.marshal(producerId);
        producerIdBytes.compact();
        coreMessage.putBytesProperty(AMQ_MSG_PRODUCER_ID, producerIdBytes.data);
    }
    final ByteSequence propBytes = messageSend.getMarshalledProperties();
    if (propBytes != null) {
        putMsgMarshalledProperties(propBytes, messageSend, coreMessage);
    }
    final ActiveMQDestination replyTo = messageSend.getReplyTo();
    if (replyTo != null) {
        putMsgReplyTo(replyTo, marshaller, coreMessage);
    }
    final String userId = messageSend.getUserID();
    if (userId != null) {
        coreMessage.putStringProperty(AMQ_MSG_USER_ID, new SimpleString(userId));
    }
    coreMessage.putBooleanProperty(AMQ_MSG_DROPPABLE, messageSend.isDroppable());
    final ActiveMQDestination origDest = messageSend.getOriginalDestination();
    if (origDest != null) {
        putMsgOriginalDestination(origDest, marshaller, coreMessage);
    }
    return coreMessage;
}
Also used : BrokerId(org.apache.activemq.command.BrokerId) ProducerId(org.apache.activemq.command.ProducerId) DataStructure(org.apache.activemq.command.DataStructure) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ByteSequence(org.apache.activemq.util.ByteSequence) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) MessageId(org.apache.activemq.command.MessageId) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 2 with DataStructure

use of org.apache.activemq.command.DataStructure in project activemq-artemis by apache.

the class OpenWireMessageConverter method setAMQMsgDataStructure.

private static void setAMQMsgDataStructure(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] dsBytes) throws IOException {
    ByteSequence seq = new ByteSequence(dsBytes);
    DataStructure ds = (DataStructure) marshaller.unmarshal(seq);
    amqMsg.setDataStructure(ds);
}
Also used : DataStructure(org.apache.activemq.command.DataStructure) ByteSequence(org.apache.activemq.util.ByteSequence)

Aggregations

DataStructure (org.apache.activemq.command.DataStructure)2 ByteSequence (org.apache.activemq.util.ByteSequence)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 BrokerId (org.apache.activemq.command.BrokerId)1 MessageId (org.apache.activemq.command.MessageId)1 ProducerId (org.apache.activemq.command.ProducerId)1