Search in sources :

Example 6 with UnsignedInteger

use of org.apache.qpid.proton.amqp.UnsignedInteger in project activemq-artemis by apache.

the class AMQPMessageTest method testVerySimple.

@Test
public void testVerySimple() {
    MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
    protonMessage.setHeader(new Header());
    Properties properties = new Properties();
    properties.setTo("someNiceLocal");
    protonMessage.setProperties(properties);
    protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7));
    protonMessage.getHeader().setDurable(Boolean.TRUE);
    protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap()));
    AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
    assertEquals(7, decoded.getHeader().getDeliveryCount().intValue());
    assertEquals(true, decoded.getHeader().getDurable());
    assertEquals("someNiceLocal", decoded.getAddress());
}
Also used : Header(org.apache.qpid.proton.amqp.messaging.Header) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 7 with UnsignedInteger

use of org.apache.qpid.proton.amqp.UnsignedInteger in project activemq-artemis by apache.

the class AMQPMessageTest method testApplicationPropertiesReencode.

@Test
public void testApplicationPropertiesReencode() {
    MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
    protonMessage.setHeader(new Header());
    Properties properties = new Properties();
    properties.setTo("someNiceLocal");
    protonMessage.setProperties(properties);
    protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7));
    protonMessage.getHeader().setDurable(Boolean.TRUE);
    HashMap map = new HashMap();
    map.put("key", "string1");
    protonMessage.setApplicationProperties(new ApplicationProperties(map));
    AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
    assertEquals("someNiceLocal", decoded.getAddress());
    decoded.setAddress("newAddress");
    decoded.reencode();
    assertEquals(7, decoded.getHeader().getDeliveryCount().intValue());
    assertEquals(true, decoded.getHeader().getDurable());
    assertEquals("newAddress", decoded.getAddress());
    assertEquals("string1", decoded.getObjectProperty("key"));
    // validate if the message will be the same after delivery
    AMQPMessage newDecoded = encodeDelivery(decoded, 3);
    assertEquals(2, decoded.getHeader().getDeliveryCount().intValue());
    assertEquals(true, newDecoded.getHeader().getDurable());
    assertEquals("newAddress", newDecoded.getAddress());
    assertEquals("string1", newDecoded.getObjectProperty("key"));
}
Also used : Header(org.apache.qpid.proton.amqp.messaging.Header) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 8 with UnsignedInteger

use of org.apache.qpid.proton.amqp.UnsignedInteger in project activemq-artemis by apache.

the class ServerJMSMapMessage method setObject.

@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());
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort)

Example 9 with UnsignedInteger

use of org.apache.qpid.proton.amqp.UnsignedInteger in project azure-service-bus-java by Azure.

the class Util method sizeof.

static int sizeof(Object obj) {
    if (obj == null) {
        return 0;
    }
    if (obj instanceof String) {
        return obj.toString().length() << 1;
    }
    if (obj instanceof Symbol) {
        return ((Symbol) obj).length() << 1;
    }
    if (obj instanceof Byte || obj instanceof UnsignedByte) {
        return Byte.BYTES;
    }
    if (obj instanceof Integer || obj instanceof UnsignedInteger) {
        return Integer.BYTES;
    }
    if (obj instanceof Long || obj instanceof UnsignedLong || obj instanceof Date) {
        return Long.BYTES;
    }
    if (obj instanceof Short || obj instanceof UnsignedShort) {
        return Short.BYTES;
    }
    if (obj instanceof Character) {
        return 4;
    }
    if (obj instanceof Float) {
        return Float.BYTES;
    }
    if (obj instanceof Double) {
        return Double.BYTES;
    }
    if (obj instanceof UUID) {
        // return 72;
        return 16;
    }
    if (obj instanceof Decimal32) {
        return 4;
    }
    if (obj instanceof Decimal64) {
        return 8;
    }
    if (obj instanceof Decimal128) {
        return 16;
    }
    if (obj instanceof Binary) {
        return ((Binary) obj).getLength();
    }
    if (obj instanceof Map) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        Map map = (Map) obj;
        for (Object value : map.keySet()) {
            size += Util.sizeof(value);
        }
        for (Object value : map.values()) {
            size += Util.sizeof(value);
        }
        return size;
    }
    if (obj instanceof Iterable) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        for (Object innerObject : (Iterable) obj) {
            size += Util.sizeof(innerObject);
        }
        return size;
    }
    if (obj.getClass().isArray()) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        int length = Array.getLength(obj);
        for (int i = 0; i < length; i++) {
            size += Util.sizeof(Array.get(obj, i));
        }
        return size;
    }
    throw new IllegalArgumentException(String.format(Locale.US, "Encoding Type: %s is not supported", obj.getClass()));
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Symbol(org.apache.qpid.proton.amqp.Symbol) Decimal64(org.apache.qpid.proton.amqp.Decimal64) Decimal128(org.apache.qpid.proton.amqp.Decimal128) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) Date(java.util.Date) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) Decimal32(org.apache.qpid.proton.amqp.Decimal32) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Binary(org.apache.qpid.proton.amqp.Binary) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UUID(java.util.UUID) Map(java.util.Map) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort)

Aggregations

UnsignedInteger (org.apache.qpid.proton.amqp.UnsignedInteger)9 Test (org.junit.Test)6 Header (org.apache.qpid.proton.amqp.messaging.Header)5 HashMap (java.util.HashMap)3 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)3 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)3 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)3 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)3 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)3 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)3 UnsignedByte (org.apache.qpid.proton.amqp.UnsignedByte)3 UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)3 UnsignedShort (org.apache.qpid.proton.amqp.UnsignedShort)3 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)3 Properties (org.apache.qpid.proton.amqp.messaging.Properties)3 URI (java.net.URI)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Connection (javax.jms.Connection)2 Message (javax.jms.Message)2