Search in sources :

Example 61 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MessageEncoder method getPayload.

public QpidByteBuffer getPayload() {
    List<QpidByteBuffer> payload = new ArrayList<>();
    if (_header != null) {
        payload.add(_header.createEncodingRetainingSection().getEncodedForm());
    }
    if (_properties != null) {
        payload.add(_properties.createEncodingRetainingSection().getEncodedForm());
    }
    if (_applicationProperties != null) {
        payload.add(new ApplicationProperties(_applicationProperties).createEncodingRetainingSection().getEncodedForm());
    }
    if (_data.isEmpty()) {
        throw new IllegalStateException("Message should have at least one data section");
    }
    List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
    if (_data.size() == 1) {
        AmqpValue amqpValue = new AmqpValue(_data.get(0));
        dataSections.add(amqpValue.createEncodingRetainingSection());
    } else {
        throw new UnsupportedOperationException("Unsupported yet");
    }
    for (EncodingRetainingSection<?> section : dataSections) {
        payload.add(section.getEncodedForm());
        section.dispose();
    }
    QpidByteBuffer combined = QpidByteBuffer.concatenate(payload);
    payload.forEach(QpidByteBuffer::dispose);
    return combined;
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Example 62 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MultiTransferTest method abortMultiTransferMessage.

// 
@Test
@SpecificationTest(section = "2.6.14", description = "The sender MAY indicate an aborted attempt to deliver a message by setting the abort flag on the last transfer." + "In this case the receiver MUST discard the message data that was transferred prior to the abort.")
public void abortMultiTransferMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final UnsignedInteger deliveryId = UnsignedInteger.ZERO;
        final Binary deliveryTag = new Binary("testTransfer".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(payloads[0]).transferDeliveryId(deliveryId).transferDeliveryTag(deliveryTag).transferMore(true).transfer().sync().transferPayload(null).transferMore(null).transferAborted(true).transfer();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        Response<?> latestResponse = interaction.consumeResponse(new Class<?>[] { null }).getLatestResponse();
        assertThat(latestResponse, is(nullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 63 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MultiTransferTest method multiTransferInterleaved.

@Test
@SpecificationTest(section = "2.6.14", description = "[...]messages being transferred along different links MAY be interleaved")
public void multiTransferInterleaved() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] messagePayload1 = Utils.splitPayload("testData1", 2);
        QpidByteBuffer[] messagePayload2 = Utils.splitPayload("testData2", 2);
        UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        Binary deliveryTag1 = new Binary("testTransfer1".getBytes(UTF_8));
        Binary deliveryTag2 = new Binary("testTransfer2".getBytes(UTF_8));
        UnsignedInteger deliverId1 = UnsignedInteger.ZERO;
        UnsignedInteger deliveryId2 = UnsignedInteger.ONE;
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachName("testLink1").attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).attachName("testLink2").attachHandle(linkHandle2).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(true).transferPayload(messagePayload1[0]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(true).transferPayload(messagePayload2[0]).transfer().sync().transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(false).transferPayload(messagePayload1[1]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(false).transferPayload(messagePayload2[1]).transfer().sync();
        for (final QpidByteBuffer payload : messagePayload1) {
            payload.dispose();
        }
        for (final QpidByteBuffer payload : messagePayload2) {
            payload.dispose();
        }
        Map<UnsignedInteger, Disposition> dispositionMap = new HashMap<>();
        for (int i = 0; i < 2; i++) {
            Disposition disposition = interaction.consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            dispositionMap.put(disposition.getFirst(), disposition);
            assertThat(disposition.getLast(), isOneOf(null, disposition.getFirst()));
            assertThat(disposition.getSettled(), is(equalTo(false)));
            assertThat(disposition.getState(), is(instanceOf(Accepted.class)));
        }
        assertThat("Unexpected number of dispositions", dispositionMap.size(), equalTo(2));
        assertThat(dispositionMap.containsKey(deliverId1), is(true));
        assertThat(dispositionMap.containsKey(deliveryId2), is(true));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 64 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_0_10Test method configureMessageContent.

private void configureMessageContent(byte[] section) {
    if (section == null) {
        section = new byte[0];
    }
    final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
    when(_handle.getContentSize()).thenReturn(section.length);
    final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
    final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
    when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 65 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method readContentBody.

private ContentHeaderBody readContentBody(final QpidByteBuffer buf) throws AMQFrameDecodingException {
    long size = buf.getUnsignedInt();
    try (QpidByteBuffer buffer = readByteBuffer(buf, size)) {
        final long newPosition = buf.position() + size;
        if (newPosition > Integer.MAX_VALUE) {
            throw new IllegalStateException(String.format("trying to advance QBB to %d which is larger than MAX_INT", newPosition));
        }
        buf.position((int) newPosition);
        return new ContentHeaderBody(buffer, size);
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)185 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)61 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)61 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)30 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)29 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 ArrayList (java.util.ArrayList)22 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)20 Test (org.junit.Test)13 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)12 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ByteBuffer (java.nio.ByteBuffer)8 LinkedHashMap (java.util.LinkedHashMap)8 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)8