Search in sources :

Example 31 with QpidByteBuffer

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);
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 32 with QpidByteBuffer

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)));
    }
}
Also used : MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ConnectionStart(org.apache.qpid.server.protocol.v0_10.transport.ConnectionStart) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 33 with QpidByteBuffer

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());
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 34 with QpidByteBuffer

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);
}
Also used : DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 35 with QpidByteBuffer

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);
    }
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

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