properties.putNullValue(key); } else if (value instanceof Boolean) { properties.putBooleanProperty(key, (Boolean) value); } else if (value instanceof Byte) { properties.putByteProperty(key, (Byte) value); } else if (value instanceof Character) { properties.putCharProperty(key, (Character) value); } else if (value instanceof Short) { properties.putShortProperty(key, (Short) value); } else if (value instanceof Integer) { properties.putIntProperty(key, (Integer) value); } else if (value instanceof Long) { properties.putLongProperty(key, (Long) value); } else if (value instanceof Float) { properties.putFloatProperty(key, (Float) value); } else if (value instanceof Double) { properties.putDoubleProperty(key, (Double) value); } else if (value instanceof String) { properties.putSimpleStringProperty(key, new SimpleString((String) value)); } else if (value instanceof SimpleString) { properties.putSimpleStringProperty(key, (SimpleString) value); } else if (value instanceof byte[]) { properties.putBytesProperty(key, (byte[]) value); } else { throw new ActiveMQPropertyConversionException(value.getClass() + " is not a valid property type");
@Override public SimpleString getSimpleStringProperty(final SimpleString key) throws ActiveMQPropertyConversionException { checkProperties(); return properties.getSimpleStringProperty(key); }
/** * I am keeping this synchronized as the decode of the Properties is lazy */ protected TypedProperties checkProperties() { if (properties == null) { TypedProperties properties = new TypedProperties(); if (buffer != null && propertiesLocation >= 0) { final ByteBuf byteBuf = buffer.duplicate().readerIndex(propertiesLocation); properties.decode(byteBuf, coreMessageObjectPools == null ? null : coreMessageObjectPools.getPropertiesDecoderPools()); } this.properties = properties; } return this.properties; }
@Override public synchronized void start() throws Exception { if (started) { return; } endpoint.openClient(); started = true; thread = new Thread(new DiscoveryRunnable(), "activemq-discovery-group-thread-" + name); thread.setDaemon(true); thread.start(); if (notificationService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("name"), new SimpleString(name)); Notification notification = new Notification(nodeID, CoreNotificationType.DISCOVERY_GROUP_STARTED, props); notificationService.sendNotification(notification); } }
private Notification createProposalNotification(SimpleString groupId, SimpleString clusterName) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, groupId); props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, clusterName); props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX); props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address); props.putIntProperty(ManagementHelper.HDR_DISTANCE, 0); return new Notification(null, CoreNotificationType.PROPOSAL, props); }
@Test public void testCopyContructor() throws Exception { props.putSimpleStringProperty(key, RandomUtil.randomSimpleString()); TypedProperties copy = new TypedProperties(props); Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize()); Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames()); Assert.assertTrue(copy.containsProperty(key)); Assert.assertEquals(props.getProperty(key), copy.getProperty(key)); }
@Test public void testRemove() throws Exception { props.putSimpleStringProperty(key, RandomUtil.randomSimpleString()); Assert.assertTrue(props.containsProperty(key)); Assert.assertNotNull(props.getProperty(key)); props.removeProperty(key); Assert.assertFalse(props.containsProperty(key)); Assert.assertNull(props.getProperty(key)); }
@Test public void testClear() throws Exception { props.putSimpleStringProperty(key, RandomUtil.randomSimpleString()); Assert.assertTrue(props.containsProperty(key)); Assert.assertNotNull(props.getProperty(key)); props.clear(); Assert.assertFalse(props.containsProperty(key)); Assert.assertNull(props.getProperty(key)); }
@Test public void testEncodeDecodeEmpty() throws Exception { TypedProperties emptyProps = new TypedProperties(); ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024); emptyProps.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); TypedProperties decodedProps = new TypedProperties(); decodedProps.decode(buffer.byteBuf()); TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps); }
@Override public CoreMessage putLongProperty(final SimpleString key, final long value) { messageChanged(); checkProperties(); properties.putLongProperty(key, value); return this; }
@Override public JMSProducer setProperty(String name, byte value) { checkName(name); properties.putByteProperty(new SimpleString(name), value); return this; }
@Test public void testClearInternalPropertiesIfAny() { TypedProperties properties = new TypedProperties(PROP_NAME::equals); properties.putBooleanProperty(PROP_NAME, RandomUtil.randomBoolean()); Assert.assertTrue(properties.clearInternalProperties()); Assert.assertFalse(properties.containsProperty(PROP_NAME)); }
@Override public Long getLongProperty(final SimpleString key) throws ActiveMQPropertyConversionException { checkProperties(); return properties.getLongProperty(key); }
@Override public Integer getIntProperty(final SimpleString key) throws ActiveMQPropertyConversionException { checkProperties(); return properties.getIntProperty(key); }
@Test public void testNullProperty() throws Exception { props.putSimpleStringProperty(key, null); Assert.assertTrue(props.containsProperty(key)); Assert.assertNull(props.getProperty(key)); }
@Override public void setInt(final String name, final int value) throws JMSException { checkName(name); map.putIntProperty(new SimpleString(name), value); invalid = true; }
@Override public CoreMessage putStringProperty(final SimpleString key, final SimpleString value) { messageChanged(); checkProperties(); properties.putSimpleStringProperty(key, value); return this; }
@Test public void testBytesPropertyWithNull() throws Exception { props.putBytesProperty(key, null); Assert.assertTrue(props.containsProperty(key)); byte[] bb = (byte[]) props.getProperty(key); Assert.assertNull(bb); }
@Test public void testSimpleStringProperty() throws Exception { SimpleString strVal = RandomUtil.randomSimpleString(); props.putSimpleStringProperty(key, strVal); Assert.assertEquals(strVal, props.getSimpleStringProperty(key)); }
public synchronized void decode(final ByteBuf buffer) { decode(buffer, null); }