org.apache.qpid.proton.amqp.UnsignedLong Java Examples
The following examples show how to use
org.apache.qpid.proton.amqp.UnsignedLong.
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: AMQPMessageIdHelper.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Takes the provided non-String AMQP message-id/correlation-id object, and * convert it it to a String usable as either a JMSMessageID or * JMSCorrelationID value, encoding the type information as a prefix to * convey for later use in reversing the process if used to set * JMSCorrelationID on a message. * * @param idObject * the object to process * @return string to be used for the actual JMS ID. */ private String convertToIdString(Object idObject) { if (idObject == null) { return null; } if (idObject instanceof UUID) { return JMS_ID_PREFIX + AMQP_UUID_PREFIX + idObject.toString(); } else if (idObject instanceof UnsignedLong) { return JMS_ID_PREFIX + AMQP_ULONG_PREFIX + idObject.toString(); } else if (idObject instanceof Binary) { ByteBuffer dup = ((Binary) idObject).asByteBuffer(); byte[] bytes = new byte[dup.remaining()]; dup.get(bytes); String hex = convertBinaryToHexString(bytes); return JMS_ID_PREFIX + AMQP_BINARY_PREFIX + hex; } else { throw new IllegalArgumentException("Unsupported type provided: " + idObject.getClass()); } }
Example #2
Source File: JmsInboundMessageDispatchTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testEqualAndHashCodeWithSameSequenceSameConsumerIdDifferentMessageIdTypes() { JmsSessionId sessionId = new JmsSessionId("con", 1); JmsConsumerId consumerId = new JmsConsumerId(sessionId, 1); Object messageId1 = new Binary(new byte[] { (byte) 1, (byte) 0 }); Object messageId2 = UnsignedLong.valueOf(2); long sequence = 1; JmsInboundMessageDispatch envelope1 = new JmsInboundMessageDispatch(sequence); envelope1.setConsumerId(consumerId); envelope1.setMessageId(messageId1); JmsInboundMessageDispatch envelope2 = new JmsInboundMessageDispatch(sequence); envelope2.setConsumerId(consumerId); envelope2.setMessageId(messageId2); assertFalse("objects should not be equal", envelope1.equals(envelope2)); assertFalse("objects should still not be equal", envelope2.equals(envelope1)); // Not strictly a requirement, but expected in this case assertNotEquals("hashCodes should not be the same", envelope1.hashCode(), envelope2.hashCode()); }
Example #3
Source File: AmqpManagementTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Some clients use Unsigned types from org.apache.qpid.proton.amqp * @throws Exception */ @Test(timeout = 60000) public void testUnsignedValues() throws Exception { int sequence = 42; LinkedHashMap<String, Object> map = new LinkedHashMap<>(); map.put("sequence", new UnsignedInteger(sequence)); ServerJMSMapMessage msg = createMapMessage(1, map, null); assertEquals(msg.getInt("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedLong(sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getLong("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedShort((short)sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getShort("sequence"), sequence); map.clear(); map.put("sequence", new UnsignedByte((byte) sequence)); msg = createMapMessage(1, map, null); assertEquals(msg.getByte("sequence"), sequence); }
Example #4
Source File: ServerJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void setObject(final String name, final Object value) throws JMSException { try { // primitives and String Object val = value; if (value instanceof UnsignedInteger) { val = ((UnsignedInteger) value).intValue(); } else if (value instanceof UnsignedShort) { val = ((UnsignedShort) value).shortValue(); } else if (value instanceof UnsignedByte) { val = ((UnsignedByte) value).byteValue(); } else if (value instanceof UnsignedLong) { val = ((UnsignedLong) value).longValue(); } TypedProperties.setObjectProperty(new SimpleString(name), val, map); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } }
Example #5
Source File: UnsignedLongTypeTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testSkipValue() { final DecoderImpl decoder = new DecoderImpl(); final EncoderImpl encoder = new EncoderImpl(decoder); AMQPDefinedTypes.registerAllTypes(decoder, encoder); final ByteBuffer buffer = ByteBuffer.allocate(64); decoder.setByteBuffer(buffer); encoder.setByteBuffer(buffer); encoder.writeUnsignedLong(UnsignedLong.ZERO); encoder.writeUnsignedLong(UnsignedLong.valueOf(1)); buffer.clear(); TypeConstructor<?> type = decoder.readConstructor(); assertEquals(UnsignedLong.class, type.getTypeClass()); type.skipValue(); UnsignedLong result = decoder.readUnsignedLong(); assertEquals(UnsignedLong.valueOf(1), result); }
Example #6
Source File: UnsignedLongType.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public void fastWrite(EncoderImpl encoder, UnsignedLong value) { long longValue = value.longValue(); if (longValue == 0) { encoder.writeRaw(EncodingCodes.ULONG0); } else if (longValue > 0 && longValue <= 255) { encoder.writeRaw(EncodingCodes.SMALLULONG); encoder.writeRaw((byte)longValue); } else { encoder.writeRaw(EncodingCodes.ULONG); encoder.writeRaw(longValue); } }
Example #7
Source File: EventBusMessage.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Serializes a correlation identifier to JSON. * <p> * Supported types for AMQP 1.0 correlation IDs are * {@code String}, {@code UnsignedLong}, {@code UUID} and {@code Binary}. * * @param id The identifier to encode. * @return The JSON representation of the identifier. * @throws NullPointerException if the correlation id is {@code null}. * @throws IllegalArgumentException if the type is not supported. */ private static JsonObject encodeIdToJson(final Object id) { Objects.requireNonNull(id); final JsonObject json = new JsonObject(); if (id instanceof String) { json.put(FIELD_CORRELATION_ID_TYPE, "string"); json.put(FIELD_CORRELATION_ID, id); } else if (id instanceof UnsignedLong) { json.put(FIELD_CORRELATION_ID_TYPE, "ulong"); json.put(FIELD_CORRELATION_ID, id.toString()); } else if (id instanceof UUID) { json.put(FIELD_CORRELATION_ID_TYPE, "uuid"); json.put(FIELD_CORRELATION_ID, id.toString()); } else if (id instanceof Binary) { json.put(FIELD_CORRELATION_ID_TYPE, "binary"); final Binary binary = (Binary) id; json.put(FIELD_CORRELATION_ID, Base64.getEncoder().encodeToString(binary.getArray())); } else { throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported"); } return json; }
Example #8
Source File: EventBusMessage.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Deserializes a correlation identifier from JSON. * <p> * Supported types for AMQP 1.0 correlation IDs are * {@code String}, {@code UnsignedLong}, {@code UUID} and {@code Binary}. * * @param json The JSON representation of the identifier. * @return The correlation identifier. * @throws NullPointerException if the JSON is {@code null}. */ private static Object decodeIdFromJson(final JsonObject json) { Objects.requireNonNull(json); final String type = json.getString(FIELD_CORRELATION_ID_TYPE); final String id = json.getString(FIELD_CORRELATION_ID); switch (type) { case "string": return id; case "ulong": return UnsignedLong.valueOf(id); case "uuid": return UUID.fromString(id); case "binary": return new Binary(Base64.getDecoder().decode(id)); default: throw new IllegalArgumentException("type " + type + " is not supported"); } }
Example #9
Source File: EncodedAmqpTypeMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public EncodedAmqpTypeMatcher(Symbol symbol, UnsignedLong code, Object expectedValue, boolean permitTrailingBytes) { _descriptorSymbol = symbol; _descriptorCode = code; _expectedValue = expectedValue; _permitTrailingBytes = permitTrailingBytes; }
Example #10
Source File: AmqpMessageIdHelperTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string * indicating an AMQP encoded ulong when given a UnsignedLong object. */ @Test public void testToMessageIdStringWithUnsignedLong() { UnsignedLong uLongMessageId = UnsignedLong.valueOf(123456789L); String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + uLongMessageId.toString(); doToMessageIdTestImpl(uLongMessageId, expected); }
Example #11
Source File: CloseMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public CloseMatcher() { super(FrameType.AMQP, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000018L), Symbol.valueOf("amqp:close:list")); }
Example #12
Source File: MessageListSectionMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public MessageListSectionMatcher(UnsignedLong numericDescriptor, Symbol symbolicDescriptor, Map<Object, Matcher<?>> fieldMatchers, boolean expectTrailingBytes) { super(numericDescriptor, symbolicDescriptor, fieldMatchers, expectTrailingBytes); }
Example #13
Source File: AmqpMessageIdHelperTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns an * UnsignedLong when given a string indicating an encoded AMQP ulong id. * * @throws Exception if an error occurs during the test. */ @Test public void testToIdObjectWithEncodedUlong() throws Exception { UnsignedLong longId = UnsignedLong.valueOf(123456789L); String provided = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "123456789"; doToIdObjectTestImpl(provided, longId); }
Example #14
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that getting the correlationId when using an underlying received message with a * ulong correlation id (using BigInteger) returns the expected value. */ @Test public void testGetCorrelationIdOnReceivedMessageWithUnsignedLong() { UnsignedLong testCorrelationId = UnsignedLong.valueOf(123456789L); String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + testCorrelationId.toString(); correlationIdOnReceivedMessageTestImpl(testCorrelationId, expected, false); }
Example #15
Source File: UnsignedLongType.java From qpid-proton-j with Apache License 2.0 | 5 votes |
public UnsignedLongEncoding getEncoding(final UnsignedLong val) { long l = val.longValue(); return l == 0L ? _zeroUnsignedLongEncoding : (l >= 0 && l <= 255L) ? _smallUnsignedLongEncoding : _unsignedLongEncoding; }
Example #16
Source File: FlowMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public FlowMatcher() { super(FrameType.AMQP, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000013L), Symbol.valueOf("amqp:flow:list")); }
Example #17
Source File: SaslResponseMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public SaslResponseMatcher() { super(FrameType.SASL, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000043L), Symbol.valueOf("amqp:sasl-response:list")); }
Example #18
Source File: AMQPMessageIdHelperTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that {@link AMQPMessageIdHelper#toIdObject(String)} returns an * UnsignedLong when given a string indicating an encoded AMQP ulong id. * * @throws Exception * if an error occurs during the test. */ @Test public void testToIdObjectWithEncodedUlong() throws Exception { UnsignedLong longId = UnsignedLong.valueOf(123456789L); String provided = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_ULONG_PREFIX + "123456789"; doToIdObjectTestImpl(provided, longId); }
Example #19
Source File: SaslOutcomeMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public SaslOutcomeMatcher() { super(FrameType.SASL, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000044L), Symbol.valueOf("amqp:sasl-outcome:list")); }
Example #20
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doCreateConsumerWithSelectorTestImpl(String messageSelector) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Matcher<?> filterMapMatcher = hasEntry(equalTo(Symbol.valueOf("jms-selector")), new DescribedTypeMatcher(UnsignedLong.valueOf(0x0000468C00000004L), Symbol.valueOf("apache.org:selector-filter:string"), equalTo(messageSelector))); SourceMatcher sourceMatcher = new SourceMatcher(); sourceMatcher.withFilter(filterMapMatcher); testPeer.expectReceiverAttach(notNullValue(), sourceMatcher); testPeer.expectLinkFlow(); testPeer.expectClose(); Queue queue = session.createQueue("myQueue"); session.createConsumer(queue, messageSelector); connection.close(); testPeer.waitForAllHandlersToComplete(3000); } }
Example #21
Source File: FrameWithPayloadMatchingHandler.java From qpid-jms with Apache License 2.0 | 5 votes |
protected FrameWithPayloadMatchingHandler(FrameType frameType, int channel, int frameSize, UnsignedLong numericDescriptor, Symbol symbolicDescriptor) { super(frameType, channel, frameSize, numericDescriptor, symbolicDescriptor); }
Example #22
Source File: UnsignedLongTypeTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetEncodingWithSmallPositiveValue() { DecoderImpl decoder = new DecoderImpl(); EncoderImpl encoder = new EncoderImpl(decoder); UnsignedLongType ult = new UnsignedLongType(encoder, decoder); //values between 0 and 255 are encoded as a specific 'small' type using a single byte UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(1L)); assertEquals("incorrect encoding returned", EncodingCodes.SMALLULONG, encoding.getEncodingCode()); }
Example #23
Source File: SaslMechanismsMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public SaslMechanismsMatcher() { super(FrameType.SASL, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000040L), Symbol.valueOf("amqp:sasl-mechanisms:list")); }
Example #24
Source File: UnsignedLongTypeTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetEncodingWithZero() { DecoderImpl decoder = new DecoderImpl(); EncoderImpl encoder = new EncoderImpl(decoder); UnsignedLongType ult = new UnsignedLongType(encoder, decoder); //values of 0 are encoded as a specific type UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(0L)); assertEquals("incorrect encoding returned", EncodingCodes.ULONG0, encoding.getEncodingCode()); }
Example #25
Source File: AttachTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testCopy() { Attach attach = new Attach(); attach.setName("test"); attach.setHandle(UnsignedInteger.ONE); attach.setRole(Role.RECEIVER); attach.setSndSettleMode(SenderSettleMode.MIXED); attach.setRcvSettleMode(ReceiverSettleMode.SECOND); attach.setSource(null); attach.setTarget(new org.apache.qpid.proton.amqp.messaging.Target()); attach.setUnsettled(null); attach.setIncompleteUnsettled(false); attach.setInitialDeliveryCount(UnsignedInteger.valueOf(42)); attach.setMaxMessageSize(UnsignedLong.valueOf(1024)); attach.setOfferedCapabilities(new Symbol[] { Symbol.valueOf("anonymous-relay") }); attach.setDesiredCapabilities(new Symbol[0]); final Attach copyOf = attach.copy(); assertEquals(attach.getName(), copyOf.getName()); assertArrayEquals(attach.getDesiredCapabilities(), copyOf.getDesiredCapabilities()); assertEquals(attach.getHandle(), copyOf.getHandle()); assertEquals(attach.getRole(), copyOf.getRole()); assertEquals(attach.getSndSettleMode(), copyOf.getSndSettleMode()); assertEquals(attach.getRcvSettleMode(), copyOf.getRcvSettleMode()); assertNull(copyOf.getSource()); assertNotNull(copyOf.getTarget()); assertEquals(attach.getUnsettled(), copyOf.getUnsettled()); assertEquals(attach.getIncompleteUnsettled(), copyOf.getIncompleteUnsettled()); assertEquals(attach.getMaxMessageSize(), copyOf.getMaxMessageSize()); assertEquals(attach.getInitialDeliveryCount(), copyOf.getInitialDeliveryCount()); assertArrayEquals(attach.getOfferedCapabilities(), copyOf.getOfferedCapabilities()); }
Example #26
Source File: AMQPMessageIdHelperTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that {@link AMQPMessageIdHelper#toMessageIdString(Object)} returns a * string indicating an AMQP encoded ulong when given a UnsignedLong object. */ @Test public void testToMessageIdStringWithUnsignedLong() { UnsignedLong uLongMessageId = UnsignedLong.valueOf(123456789L); String expected = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_ULONG_PREFIX + uLongMessageId.toString(); doToMessageIdTestImpl(uLongMessageId, expected); }
Example #27
Source File: DispositionMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public DispositionMatcher() { super(FrameType.AMQP, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000015L), Symbol.valueOf("amqp:disposition:list")); }
Example #28
Source File: MessageMapSectionMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public MessageMapSectionMatcher(UnsignedLong numericDescriptor, Symbol symbolicDescriptor, Map<Object, Matcher<?>> fieldMatchers, boolean expectTrailingBytes) { super(numericDescriptor, symbolicDescriptor, fieldMatchers, expectTrailingBytes); }
Example #29
Source File: DetachMatcher.java From qpid-jms with Apache License 2.0 | 5 votes |
public DetachMatcher() { super(FrameType.AMQP, ANY_CHANNEL, UnsignedLong.valueOf(0x0000000000000016L), Symbol.valueOf("amqp:detach:list")); }
Example #30
Source File: AMQPMessageIdHelper.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Takes the provided id string and return the appropriate amqp messageId * style object. Converts the type based on any relevant encoding information * found as a prefix. * * @param origId * the object to be converted * @return the AMQP messageId style object * * @throws ActiveMQAMQPIllegalStateException * if the provided baseId String indicates an encoded type but can't * be converted to that type. */ public Object toIdObject(final String origId) throws ActiveMQAMQPIllegalStateException { if (origId == null) { return null; } if (!AMQPMessageIdHelper.INSTANCE.hasMessageIdPrefix(origId)) { // We have a string without any "ID:" prefix, it is an // application-specific String, use it as-is. return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { // Prefix telling us there was originally no "ID:" prefix, // strip it and return the remainder return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { // We have a string without any encoding prefix needing processed, // so transmit it as-is, including the "ID:" return origId; } } catch (IllegalArgumentException iae) { throw new ActiveMQAMQPIllegalStateException(iae.getMessage()); } }