Search in sources :

Example 1 with AMQFrame

use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame 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)

Example 2 with AMQFrame

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

the class Interaction method sendPerformative.

public Interaction sendPerformative(int channel, final AMQBody amqBody) throws Exception {
    final AMQFrame frameBody = new AMQFrame(channel, amqBody);
    sendPerformativeAndChainFuture(frameBody);
    return this;
}
Also used : AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)

Example 3 with AMQFrame

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

the class ProtocolOutputConverterImpl method writeMessageDeliveryUnchanged.

private void writeMessageDeliveryUnchanged(MessageContentSource content, int channelId, AMQBody deliverBody, ContentHeaderBody contentHeaderBody, int bodySize) {
    if (bodySize == 0) {
        SmallCompositeAMQBodyBlock compositeBlock = new SmallCompositeAMQBodyBlock(channelId, deliverBody, contentHeaderBody);
        writeFrame(compositeBlock);
    } else {
        int maxBodySize = (int) _connection.getMaxFrameSize() - AMQFrame.getFrameOverhead();
        int capacity = bodySize > maxBodySize ? maxBodySize : bodySize;
        int writtenSize = capacity;
        AMQBody firstContentBody = new MessageContentSourceBody(content, 0, capacity);
        CompositeAMQBodyBlock compositeBlock = new CompositeAMQBodyBlock(channelId, deliverBody, contentHeaderBody, firstContentBody);
        writeFrame(compositeBlock);
        while (writtenSize < bodySize) {
            capacity = bodySize - writtenSize > maxBodySize ? maxBodySize : bodySize - writtenSize;
            AMQBody body = new MessageContentSourceBody(content, writtenSize, capacity);
            writtenSize += capacity;
            writeFrame(new AMQFrame(channelId, body));
        }
    }
}
Also used : AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)

Example 4 with AMQFrame

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

the class AMQDecoderTest method testMultiplePartialFrameDecode.

public void testMultiplePartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
    ByteBuffer msgA = getHeartbeatBodyBuffer();
    ByteBuffer msgB = getHeartbeatBodyBuffer();
    ByteBuffer msgC = getHeartbeatBodyBuffer();
    ByteBuffer sliceA = ByteBuffer.allocate(msgA.remaining() + msgB.remaining() / 2);
    sliceA.put(msgA);
    int limit = msgB.limit();
    int pos = msgB.remaining() / 2;
    msgB.limit(pos);
    sliceA.put(msgB);
    sliceA.flip();
    msgB.limit(limit);
    msgB.position(pos);
    ByteBuffer sliceB = ByteBuffer.allocate(msgB.remaining() + pos);
    sliceB.put(msgB);
    msgC.limit(pos);
    sliceB.put(msgC);
    sliceB.flip();
    msgC.limit(limit);
    _decoder.decodeBuffer(sliceA);
    List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
    assertEquals(1, frames.size());
    frames.clear();
    _decoder.decodeBuffer(sliceB);
    assertEquals(1, frames.size());
    frames.clear();
    _decoder.decodeBuffer(msgC);
    assertEquals(1, frames.size());
    for (AMQDataBlock frame : frames) {
        if (frame instanceof AMQFrame) {
            assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frame).getBodyFrame().getFrameType());
        } else {
            fail("decode was not a frame");
        }
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 5 with AMQFrame

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

the class AMQDecoderTest method testPartialFrameDecode.

public void testPartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
    ByteBuffer msg = getHeartbeatBodyBuffer();
    ByteBuffer msgA = msg.slice();
    int msgbPos = msg.remaining() / 2;
    int msgaLimit = msg.remaining() - msgbPos;
    msgA.limit(msgaLimit);
    msg.position(msgbPos);
    ByteBuffer msgB = msg.slice();
    _decoder.decodeBuffer(msgA);
    List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
    assertEquals(0, frames.size());
    _decoder.decodeBuffer(msgB);
    assertEquals(1, frames.size());
    if (frames.get(0) instanceof AMQFrame) {
        assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
    } else {
        fail("decode was not a frame");
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)7 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)7 ByteBuffer (java.nio.ByteBuffer)6 AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)3 ArrayList (java.util.ArrayList)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 Random (java.util.Random)1 BasicPublishBody (org.apache.qpid.server.protocol.v0_8.transport.BasicPublishBody)1 CompositeAMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.CompositeAMQDataBlock)1 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)1 ProtocolInitiation (org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation)1 ByteBufferSender (org.apache.qpid.server.transport.ByteBufferSender)1 HeaderResponse (org.apache.qpid.tests.protocol.HeaderResponse)1 Response (org.apache.qpid.tests.protocol.Response)1