use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class Disassembler method frame.
private void frame(byte flags, byte type, byte track, int channel, int size, ByteBuffer buffer) {
ByteBuffer data = ByteBuffer.allocate(HEADER_SIZE);
data.put(0, flags);
data.put(1, type);
data.putShort(2, (short) (size + HEADER_SIZE));
data.put(4, (byte) 0);
data.put(5, track);
data.putShort(6, (short) channel);
try (QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(data)) {
_sender.send(qpidByteBuffer);
}
if (size > 0) {
final ByteBuffer view = view(buffer, 0, size);
try (QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(view)) {
_sender.send(qpidByteBuffer);
}
buffer.position(buffer.position() + size);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class LargeMessageBodyTest method messageBodyOverManyFrames.
@Test
public void messageBodyOverManyFrames() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
final String subscriberName = "testSubscriber";
byte[] sessionName = "test".getBytes(UTF_8);
ConnectionTune tune = interaction.negotiateProtocol().consumeResponse().consumeResponse(ConnectionStart.class).connection().startOkMechanism(ConnectionInteraction.SASL_MECHANISM_ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTune.class);
final byte[] messageContent = new byte[tune.getMaxFrameSize() * 2];
IntStream.range(0, messageContent.length).forEach(i -> {
messageContent[i] = (byte) (i & 0xFF);
});
interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentLength(messageContent.length);
interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferBody(messageContent).transferHeader(null, messageProperties).transferId(3).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
MessageTransfer transfer = consumeResponse(interaction, MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
assertThat(transfer.getBodySize(), is(equalTo(messageContent.length)));
QpidByteBuffer receivedBody = transfer.getBody();
byte[] receivedBytes = new byte[receivedBody.remaining()];
receivedBody.get(receivedBytes);
assertThat(receivedBytes, is(equalTo(messageContent)));
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class ClientDecoder method decodeBuffer.
public void decodeBuffer(ByteBuffer incomingBuffer) throws AMQFrameDecodingException, AMQProtocolVersionException {
if (_incompleteBuffer == null) {
QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(incomingBuffer);
final int required = decode(qpidByteBuffer);
if (required != 0) {
_incompleteBuffer = QpidByteBuffer.allocate(qpidByteBuffer.remaining() + required);
_incompleteBuffer.put(qpidByteBuffer);
}
qpidByteBuffer.dispose();
} else {
if (incomingBuffer.remaining() < _incompleteBuffer.remaining()) {
_incompleteBuffer.put(incomingBuffer);
} else {
_incompleteBuffer.flip();
final QpidByteBuffer aggregatedBuffer = QpidByteBuffer.allocate(_incompleteBuffer.remaining() + incomingBuffer.remaining());
aggregatedBuffer.put(_incompleteBuffer);
aggregatedBuffer.put(incomingBuffer);
aggregatedBuffer.flip();
final int required = decode(aggregatedBuffer);
_incompleteBuffer.dispose();
if (required != 0) {
_incompleteBuffer = QpidByteBuffer.allocate(aggregatedBuffer.remaining() + required);
_incompleteBuffer.put(aggregatedBuffer);
} else {
_incompleteBuffer = null;
}
aggregatedBuffer.dispose();
}
}
// post-condition: assert(!incomingBuffer.hasRemaining());
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final byte[] content) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, content == null ? 0 : content.length);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null) {
Binary binary = new Binary(content);
DataSection dataSection = new Data(binary).createEncodingRetainingSection();
QpidByteBuffer qbb = dataSection.getEncodedForm();
int length = qbb.remaining();
when(storedMessage.getContentSize()).thenReturn(length);
when(storedMessage.getContent(0, length)).thenReturn(qbb);
} else {
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_1_0Test method doTest.
private void doTest(final byte[] messageBytes, final String mimeType, final Class<? extends EncodingRetainingSection<?>> expectedBodySection, final Object expectedContent, final Symbol expectedContentType, final Byte expectedJmsTypeAnnotation) throws Exception {
final AMQMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
EncodingRetainingSection<?> encodingRetainingSection = sections.get(0);
assertEquals("Unexpected section type", expectedBodySection, encodingRetainingSection.getClass());
if (expectedContent instanceof byte[]) {
assertArrayEquals("Unexpected content", ((byte[]) expectedContent), ((Binary) encodingRetainingSection.getValue()).getArray());
} else {
assertEquals("Unexpected content", expectedContent, encodingRetainingSection.getValue());
}
Symbol contentType = getContentType(convertedMessage);
if (expectedContentType == null) {
assertNull("Content type should be null", contentType);
} else {
assertEquals("Unexpected content type", expectedContentType, contentType);
}
Byte jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(convertedMessage);
if (expectedJmsTypeAnnotation == null) {
assertNull("Unexpected annotation 'x-opt-jms-msg-type'", jmsMessageTypeAnnotation);
} else {
assertEquals("Unexpected annotation 'x-opt-jms-msg-type'", expectedJmsTypeAnnotation, jmsMessageTypeAnnotation);
}
}
Aggregations