Java Code Examples for org.apache.qpid.proton.amqp.messaging.Header#setFirstAcquirer()

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Header#setFirstAcquirer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public Header newInstance(Object described)
{
    List l = (List) described;

    Header o = new Header();


    switch(5 - l.size())
    {

        case 0:
            o.setDeliveryCount( (UnsignedInteger) l.get( 4 ) );
        case 1:
            o.setFirstAcquirer( (Boolean) l.get( 3 ) );
        case 2:
            o.setTtl( (UnsignedInteger) l.get( 2 ) );
        case 3:
            o.setPriority( (UnsignedByte) l.get( 1 ) );
        case 4:
            o.setDurable( (Boolean) l.get( 0 ) );
    }


    return o;
}
 
Example 2
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkHeader() throws IOException {
    Header header = new Header();
    header.setDurable(true);
    header.setFirstAcquirer(true);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(header);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("Header", resultSet);
}
 
Example 3
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetHeader() {
   MessageImpl protonMessage = createProtonMessage();
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   Header decoded = message.getHeader();
   assertNotSame(decoded, protonMessage.getHeader());
   assertHeaderEquals(protonMessage.getHeader(), decoded);

   // Update the values
   decoded.setDeliveryCount(UnsignedInteger.ZERO);
   decoded.setTtl(UnsignedInteger.valueOf(255));
   decoded.setFirstAcquirer(true);

   // Check that the message is unaffected.
   assertHeaderNotEquals(protonMessage.getHeader(), decoded);
}
 
Example 4
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateFromHeader() {
    Header protonHeader = new Header();
    protonHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    protonHeader.setTtl(UnsignedInteger.valueOf(10));
    protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    protonHeader.setDurable(true);
    protonHeader.setFirstAcquirer(true);

    AmqpHeader header = new AmqpHeader(protonHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example 5
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithFirstAcquirerHeader() {
    AmqpHeader header = new AmqpHeader();

    Header protonHeader = new Header();
    protonHeader.setFirstAcquirer(true);

    header.setHeader(protonHeader);

    assertFalse(header.isDefault());
    assertFalse(header.nonDefaultDurable());
    assertFalse(header.nonDefaultPriority());
    assertFalse(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertFalse(header.nonDefaultDeliveryCount());

    assertEquals(false, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(4, header.getPriority());
    assertEquals(0, header.getTimeToLive());
    assertEquals(0, header.getDeliveryCount());
}
 
Example 6
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithHeaderWithAllSet() {
    AmqpHeader header = new AmqpHeader();

    Header protonHeader = new Header();
    protonHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    protonHeader.setTtl(UnsignedInteger.valueOf(10));
    protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    protonHeader.setDurable(true);
    protonHeader.setFirstAcquirer(true);

    header.setHeader(protonHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example 7
Source File: HeaderTypeCodecTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void doTestDecodeHeaderSeries(int size) throws IOException {
    Header header = new Header();

    header.setDurable(Boolean.TRUE);
    header.setPriority(UnsignedByte.valueOf((byte) 3));
    header.setDeliveryCount(UnsignedInteger.valueOf(10));
    header.setFirstAcquirer(Boolean.FALSE);
    header.setTtl(UnsignedInteger.valueOf(500));

    for (int i = 0; i < size; ++i) {
        encoder.writeObject(header);
    }

    buffer.clear();

    for (int i = 0; i < size; ++i) {
        final Object result = decoder.readObject();

        assertNotNull(result);
        assertTrue(result instanceof Header);

        Header decoded = (Header) result;

        assertEquals(3, decoded.getPriority().intValue());
        assertTrue(decoded.getDurable().booleanValue());
    }
}
 
Example 8
Source File: HeaderTypeCodecTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecodeHeaderArray() throws IOException {
    Header header = new Header();

    header.setDurable(Boolean.TRUE);
    header.setPriority(UnsignedByte.valueOf((byte) 3));
    header.setDeliveryCount(UnsignedInteger.valueOf(10));
    header.setFirstAcquirer(Boolean.FALSE);
    header.setTtl(UnsignedInteger.valueOf(500));

    Header[] source = new Header[32];

    for (int i = 0; i < source.length; ++i) {
        source[i] = header;
    }

    encoder.writeObject(source);

    buffer.clear();

    final Object result = decoder.readObject();

    assertNotNull(result);
    assertTrue(result.getClass().isArray());

    final Object[] resultArray = (Object[]) result;

    for (int i = 0; i < source.length; ++i) {

        assertTrue(resultArray[i] instanceof Header);

        Header decoded = (Header) resultArray[i];

        assertEquals(3, decoded.getPriority().intValue());
        assertTrue(decoded.getDurable().booleanValue());
        assertEquals(header.getDeliveryCount(), decoded.getDeliveryCount());
    }
}
 
Example 9
Source File: FastPathHeaderType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Header readValue() {
    DecoderImpl decoder = getDecoder();
    ReadableBuffer buffer = decoder.getBuffer();
    byte typeCode = decoder.getBuffer().get();

    @SuppressWarnings("unused")
    int size = 0;
    int count = 0;

    switch (typeCode) {
        case EncodingCodes.LIST0:
            break;
        case EncodingCodes.LIST8:
            size = buffer.get() & 0xff;
            count = buffer.get() & 0xff;
            break;
        case EncodingCodes.LIST32:
            size = buffer.getInt();
            count = buffer.getInt();
            break;
        default:
            throw new DecodeException("Incorrect type found in Header encoding: " + typeCode);
    }

    Header header = new Header();

    for (int index = 0; index < count; ++index) {
        switch (index) {
            case 0:
                header.setDurable(decoder.readBoolean(null));
                break;
            case 1:
                header.setPriority(decoder.readUnsignedByte(null));
                break;
            case 2:
                header.setTtl(decoder.readUnsignedInteger(null));
                break;
            case 3:
                header.setFirstAcquirer(decoder.readBoolean(null));
                break;
            case 4:
                header.setDeliveryCount(decoder.readUnsignedInteger(null));
                break;
            default:
                throw new IllegalStateException("To many entries in Header encoding");
        }
    }

    return header;
}
 
Example 10
Source File: HeaderBenchmark.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void initHeader()
{
    header = new Header();
    header.setDurable(true);
    header.setFirstAcquirer(true);
}