• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UnsignedLong类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.qpid.proton.amqp.UnsignedLong的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLong类的具体用法?Java UnsignedLong怎么用?Java UnsignedLong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnsignedLong类属于org.apache.qpid.proton.amqp包,在下文中一共展示了UnsignedLong类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: encodeIdToJson

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * Encodes the given ID object to JSON representation. Supported types for AMQP 1.0 correlation/messageIds are
 * String, UnsignedLong, UUID and Binary.
 * 
 * @param id The identifier to encode to JSON
 * @return A JsonObject containing the JSON representation of the identifier.
 * @throws IllegalArgumentException if the type is not supported
 */
public static JsonObject encodeIdToJson(final Object id) {

    final JsonObject json = new JsonObject();
    if (id instanceof String) {
        json.put("type", "string");
        json.put("id", id);
    } else if (id instanceof UnsignedLong) {
        json.put("type", "ulong");
        json.put("id", id.toString());
    } else if (id instanceof UUID) {
        json.put("type", "uuid");
        json.put("id", id.toString());
    } else if (id instanceof Binary) {
        json.put("type", "binary");
        final Binary binary = (Binary) id;
        json.put("id", Base64.getEncoder().encodeToString(binary.getArray()));
    } else {
        throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported");
    }
    return json;
}
 
开发者ID:eclipse,项目名称:hono,代码行数:30,代码来源:MessageHelper.java


示例2: decodeIdFromJson

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * Decodes the given JsonObject to JSON representation.
 * Supported types for AMQP 1.0 correlation/messageIds are String, UnsignedLong, UUID and Binary.
 * @param json JSON representation of an ID
 * @return an ID object of correct type
 */
public static Object decodeIdFromJson(final JsonObject json)
{
    final String type = json.getString("type");
    final String id = json.getString("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");
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:24,代码来源:MessageHelper.java


示例3: fastWrite

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:19,代码来源:UnsignedLongType.java


示例4: readUnsignedLong

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public UnsignedLong readUnsignedLong(final UnsignedLong defaultVal)
{
    byte encodingCode = _buffer.get();

    switch (encodingCode)
    {
        case EncodingCodes.ULONG0:
            return UnsignedLong.ZERO;
        case EncodingCodes.SMALLULONG:
            return (UnsignedLong) _constructors[EncodingCodes.SMALLULONG & 0xff].readValue();
        case EncodingCodes.ULONG:
            return (UnsignedLong) _constructors[EncodingCodes.ULONG & 0xff].readValue();
        case EncodingCodes.NULL:
            return defaultVal;
        default:
            throw new DecodeException("Expected UnsignedLong type but found encoding: " + encodingCode);
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:19,代码来源:DecoderImpl.java


示例5: testSkipValue

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:UnsignedLongTypeTest.java


示例6: convertToIdString

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * 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());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:34,代码来源:AMQPMessageIdHelper.java


示例7: convertToIdString

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:32,代码来源:AmqpMessageIdHelper.java


示例8: testEqualAndHashCodeWithSameSequenceSameConsumerIdDifferentMessageIdTypes

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:23,代码来源:JmsInboundMessageDispatchTest.java


示例9: messageIdOnReceivedMessageTestImpl

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
private void messageIdOnReceivedMessageTestImpl(Object underlyingMessageId, String expected) {
    if (!(underlyingMessageId == null || underlyingMessageId instanceof Binary
            || underlyingMessageId instanceof UnsignedLong || underlyingMessageId instanceof String || underlyingMessageId instanceof UUID)) {
        throw new IllegalArgumentException("invalid id type");
    }

    Message message = Proton.message();

    Properties props = new Properties();
    props.setMessageId(underlyingMessageId);
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertNotNull("Expected a messageId on received message", amqpMessageFacade.getMessageId());

    assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:19,代码来源:AmqpJmsMessageFacadeTest.java


示例10: UnsignedLongType

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
UnsignedLongType(final EncoderImpl encoder, final DecoderImpl decoder)
{
    _unsignedLongEncoding = new AllUnsignedLongEncoding(encoder, decoder);
    _smallUnsignedLongEncoding = new SmallUnsignedLongEncoding(encoder, decoder);
    _zeroUnsignedLongEncoding = new ZeroUnsignedLongEncoding(encoder, decoder);
    encoder.register(UnsignedLong.class, this);
    decoder.register(this);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:9,代码来源:UnsignedLongType.java


示例11: getEncoding

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public UnsignedLongEncoding getEncoding(final UnsignedLong val)
{
    long l = val.longValue();
    return l == 0L
        ? _zeroUnsignedLongEncoding
        : (l >= 0 && l <= 255L) ? _smallUnsignedLongEncoding : _unsignedLongEncoding;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:8,代码来源:UnsignedLongType.java


示例12: writeUnsignedLong

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public void writeUnsignedLong(final UnsignedLong ulong)
{
    if(ulong == null)
    {
        writeNull();
    }
    else
    {
        _unsignedLongType.fastWrite(this, ulong);
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:12,代码来源:EncoderImpl.java


示例13: testGetEncodingWithZero

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:12,代码来源:UnsignedLongTypeTest.java


示例14: testGetEncodingWithSmallPositiveValue

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:12,代码来源:UnsignedLongTypeTest.java


示例15: testGetEncodingWithTwoToSixtyThree

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testGetEncodingWithTwoToSixtyThree()
{
    DecoderImpl decoder = new DecoderImpl();
    EncoderImpl encoder = new EncoderImpl(decoder);
    UnsignedLongType ult = new UnsignedLongType(encoder, decoder);

    BigInteger bigInt = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
    UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(bigInt));
    assertEquals("incorrect encoding returned", EncodingCodes.ULONG, encoding.getEncodingCode());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:12,代码来源:UnsignedLongTypeTest.java


示例16: toIdObject

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * 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 IllegalArgument
 *         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());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:51,代码来源:AMQPMessageIdHelper.java


示例17: getObjectProperty

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Override
public Object getObjectProperty(String key) {
   if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) {
      if (getProperties() != null) {
         return getProperties().getSubject();
      }
   } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) {
      return getConnectionID();
   } else if (key.equals(MessageUtil.JMSXGROUPID)) {
      return getGroupID();
   } else if (key.equals(MessageUtil.JMSXUSERID)) {
      return getAMQPUserID();
   } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) {
      if (getProperties() != null && getProperties().getCorrelationId() != null) {
         return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(getProperties().getCorrelationId());
      }
   } else {
      Object value = getApplicationPropertiesMap().get(key);
      if (value instanceof UnsignedInteger ||
          value instanceof UnsignedByte ||
          value instanceof UnsignedLong ||
          value instanceof UnsignedShort) {
         return ((Number)value).longValue();
      } else {
         return value;
      }
   }

   return null;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:31,代码来源:AMQPMessage.java


示例18: testToMessageIdStringWithUnsignedLong

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:12,代码来源:AMQPMessageIdHelperTest.java


示例19: testToCorrelationIdStringWithUnsignedLong

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * Test that {@link AMQPMessageIdHelper#toCorrelationIdString(Object)}
 * returns a string indicating an AMQP encoded ulong when given a
 * UnsignedLong object.
 */
@Test
public void testToCorrelationIdStringWithUnsignedLong() {
   UnsignedLong uLongCorrelationId = UnsignedLong.valueOf(123456789L);
   String expected = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_ULONG_PREFIX + uLongCorrelationId.toString();

   doToCorrelationIDTestImpl(uLongCorrelationId, expected);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:AMQPMessageIdHelperTest.java


示例20: testToIdObjectWithEncodedUlong

import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:15,代码来源:AMQPMessageIdHelperTest.java



注:本文中的org.apache.qpid.proton.amqp.UnsignedLong类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IPFailoverProxyProvider类代码示例发布时间:2022-05-22
下一篇:
Java SimpleDecoder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap