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;
}
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()));
}
}
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));
}
}
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()));
}
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);
}
}
Aggregations