NO-JIRA Save double property lookup on common case
This commit is contained in:
parent
377cda62b2
commit
95d2de5aa4
|
@ -23,10 +23,12 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException;
|
||||
|
@ -169,10 +171,12 @@ public class TypedProperties {
|
|||
throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
|
||||
}
|
||||
|
||||
public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
|
||||
public Byte getByteProperty(final SimpleString key,
|
||||
final Supplier<Byte> defaultValue) throws ActiveMQPropertyConversionException {
|
||||
Objects.requireNonNull(defaultValue);
|
||||
Object value = doGetProperty(key);
|
||||
if (value == null) {
|
||||
return Byte.valueOf(null);
|
||||
return defaultValue.get();
|
||||
} else if (value instanceof Byte) {
|
||||
return (Byte) value;
|
||||
} else if (value instanceof SimpleString) {
|
||||
|
@ -181,6 +185,10 @@ public class TypedProperties {
|
|||
throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
|
||||
}
|
||||
|
||||
public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
|
||||
return getByteProperty(key, () -> Byte.valueOf(null));
|
||||
}
|
||||
|
||||
public Character getCharProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
|
||||
Object value = doGetProperty(key);
|
||||
if (value == null) {
|
||||
|
|
|
@ -115,6 +115,18 @@ public class TypedPropertiesConversionTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoByteProperty() {
|
||||
Assert.assertEquals(0, props.size());
|
||||
Assert.assertNull(props.getByteProperty(key, () -> null));
|
||||
props.putByteProperty(key.concat('0'), RandomUtil.randomByte());
|
||||
Assert.assertEquals(1, props.size());
|
||||
Assert.assertNull(props.getByteProperty(key, () -> null));
|
||||
props.putNullValue(key);
|
||||
Assert.assertTrue(props.containsProperty(key));
|
||||
Assert.assertNull(props.getByteProperty(key, () -> null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntProperty() throws Exception {
|
||||
Integer val = RandomUtil.randomInt();
|
||||
|
|
|
@ -154,10 +154,11 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage {
|
|||
|
||||
@Override
|
||||
public RoutingType getRoutingType() {
|
||||
if (containsProperty(Message.HDR_ROUTING_TYPE)) {
|
||||
return RoutingType.getType(getByteProperty(Message.HDR_ROUTING_TYPE));
|
||||
final Byte maybeByte = getProperties().getByteProperty(Message.HDR_ROUTING_TYPE, () -> null);
|
||||
if (maybeByte == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return RoutingType.getType(maybeByte);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue