Search in sources :

Example 1 with CompositeAMQDataBlock

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

the class BasicInteraction method publishMessage.

public Interaction publishMessage() throws Exception {
    List<AMQFrame> frames = new ArrayList<>();
    BasicPublishBody publishFrame = new BasicPublishBody(0, AMQShortString.valueOf(_publishExchange), AMQShortString.valueOf(_publishRoutingKey), _publishMandatory, _publishImmediate);
    frames.add(new AMQFrame(_interaction.getChannelId(), publishFrame));
    final BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
    basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(_contentHeaderPropertiesHeaders));
    basicContentHeaderProperties.setContentType(_contentHeaderPropertiesContentType);
    basicContentHeaderProperties.setDeliveryMode(_contentHeaderPropertiesDeliveryMode);
    basicContentHeaderProperties.setPriority(_contentHeaderPropertiesPriority);
    final int contentSize = _content == null ? 0 : _content.length;
    ContentHeaderBody contentHeaderBody = new ContentHeaderBody(basicContentHeaderProperties, contentSize);
    frames.add(new AMQFrame(_interaction.getChannelId(), contentHeaderBody));
    if (contentSize > 0) {
        final byte[] contentCopy = new byte[contentSize];
        System.arraycopy(_content, 0, contentCopy, 0, contentSize);
        final int framePayloadMax = _interaction.getMaximumFrameSize() - 8;
        int offset = 0;
        do {
            int contentToCopyLength = Math.min(framePayloadMax, contentSize - offset);
            ContentBody contentBody = new ContentBody(ByteBuffer.wrap(contentCopy, offset, contentToCopyLength));
            frames.add(new AMQFrame(_interaction.getChannelId(), contentBody));
            offset += contentToCopyLength;
        } while (offset < contentSize);
    }
    CompositeAMQDataBlock frame = new CompositeAMQDataBlock(frames.toArray(new AMQFrame[frames.size()]));
    return _interaction.sendPerformative(frame);
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) ArrayList(java.util.ArrayList) CompositeAMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.CompositeAMQDataBlock) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) BasicPublishBody(org.apache.qpid.server.protocol.v0_8.transport.BasicPublishBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Aggregations

ArrayList (java.util.ArrayList)1 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)1 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)1 BasicPublishBody (org.apache.qpid.server.protocol.v0_8.transport.BasicPublishBody)1 CompositeAMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.CompositeAMQDataBlock)1 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)1 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)1