Java Code Examples for org.apache.qpid.proton.amqp.messaging.Header#setTtl()
The following examples show how to use
org.apache.qpid.proton.amqp.messaging.Header#setTtl() .
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 |
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: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@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 3
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testGetTtlSynthesizedExpirationOnReceivedMessageWithTtlButNoAbsoluteExpiration() throws JMSException { Long ttl = 123L; Message message = Proton.message(); Header header = new Header(); header.setTtl(UnsignedInteger.valueOf(ttl)); message.setHeader(header); long start = System.currentTimeMillis(); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); long end = System.currentTimeMillis(); long expiration = amqpMessageFacade.getExpiration(); assertTrue("Should have sythesized expiration based on current time + ttl", start + ttl <= expiration); assertTrue("Should have sythesized expiration based on current time + ttl", expiration <= end + ttl); long expiration2 = amqpMessageFacade.getExpiration(); assertEquals("Second retrieval should return same result", expiration, expiration2); amqpMessageFacade = amqpMessageFacade.copy(); long expiration3 = amqpMessageFacade.getExpiration(); assertEquals("Thrid retrieval from copy should return same result", expiration, expiration3); }
Example 4
Source File: AmqpHeaderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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 |
@Test public void testSetHeaderWithTimeToLiveHeader() { AmqpHeader header = new AmqpHeader(); Header protonHeader = new Header(); protonHeader.setTtl(UnsignedInteger.valueOf(9)); header.setHeader(protonHeader); assertFalse(header.isDefault()); assertFalse(header.nonDefaultDurable()); assertFalse(header.nonDefaultPriority()); assertTrue(header.nonDefaultTimeToLive()); assertFalse(header.nonDefaultFirstAcquirer()); assertFalse(header.nonDefaultDeliveryCount()); assertEquals(false, header.isDurable()); assertEquals(false, header.isFirstAcquirer()); assertEquals(4, header.getPriority()); assertEquals(9, header.getTimeToLive()); assertEquals(0, header.getDeliveryCount()); }
Example 6
Source File: AmqpHeaderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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 |
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 |
@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 |
@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; }