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());
}
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"));
}
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());
}
}
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()));
}
Aggregations