From 2e0f051d2d5a7eb3005053ee097570142eb0398e Mon Sep 17 00:00:00 2001 From: franz1981 Date: Tue, 12 Jan 2021 12:07:23 +0100 Subject: [PATCH] ARTEMIS-3063 AMQPMessage get property can use a String switch --- .../activemq/artemis/reader/MessageUtil.java | 12 +++-- .../protocol/amqp/broker/AMQPMessage.java | 54 ++++++++++--------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/MessageUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/MessageUtil.java index 198a933d95..4e4d3e5928 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/MessageUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/MessageUtil.java @@ -33,11 +33,15 @@ import org.apache.activemq.artemis.api.core.SimpleString; */ public class MessageUtil { - public static final SimpleString CORRELATIONID_HEADER_NAME = new SimpleString("JMSCorrelationID"); + public static final String CORRELATIONID_HEADER_NAME_STRING = "JMSCorrelationID"; + + public static final SimpleString CORRELATIONID_HEADER_NAME = new SimpleString(CORRELATIONID_HEADER_NAME_STRING); public static final SimpleString REPLYTO_HEADER_NAME = new SimpleString("JMSReplyTo"); - public static final SimpleString TYPE_HEADER_NAME = new SimpleString("JMSType"); + public static final String TYPE_HEADER_NAME_STRING = "JMSType"; + + public static final SimpleString TYPE_HEADER_NAME = new SimpleString(TYPE_HEADER_NAME_STRING); public static final SimpleString JMS = new SimpleString("JMS"); @@ -53,7 +57,9 @@ public class MessageUtil { public static final String JMSXUSERID = "JMSXUserID"; - public static final SimpleString CONNECTION_ID_PROPERTY_NAME = new SimpleString("__AMQ_CID"); + public static final String CONNECTION_ID_PROPERTY_NAME_STRING = "__AMQ_CID"; + + public static final SimpleString CONNECTION_ID_PROPERTY_NAME = new SimpleString(CONNECTION_ID_PROPERTY_NAME_STRING); // public static ActiveMQBuffer getBodyBuffer(Message message) { // return message.getBodyBuffer(); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java index bde844e0aa..2c4f8d8e66 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java @@ -1365,27 +1365,28 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. @Override public final Object getObjectProperty(String key) { - if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { - if (properties != null) { - return properties.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.JMSXGROUPSEQ)) { - return getGroupSequence(); - } else if (key.equals(MessageUtil.JMSXUSERID)) { - return getAMQPUserID(); - } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) { - if (properties != null && properties.getCorrelationId() != null) { - return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(properties.getCorrelationId()); - } - } else { - return getApplicationObjectProperty(key); + switch (key) { + case MessageUtil.TYPE_HEADER_NAME_STRING: + if (properties != null) { + return properties.getSubject(); + } + return null; + case MessageUtil.CONNECTION_ID_PROPERTY_NAME_STRING: + return getConnectionID(); + case MessageUtil.JMSXGROUPID: + return getGroupID(); + case MessageUtil.JMSXGROUPSEQ: + return getGroupSequence(); + case MessageUtil.JMSXUSERID: + return getAMQPUserID(); + case MessageUtil.CORRELATIONID_HEADER_NAME_STRING: + if (properties != null && properties.getCorrelationId() != null) { + return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(properties.getCorrelationId()); + } + return null; + default: + return getApplicationObjectProperty(key); } - - return null; } private Object getApplicationObjectProperty(String key) { @@ -1414,12 +1415,13 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. @Override public final String getStringProperty(String key) throws ActiveMQPropertyConversionException { - if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { - return properties.getSubject(); - } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) { - return getConnectionID(); - } else { - return (String) getApplicationPropertiesMap(false).get(key); + switch (key) { + case MessageUtil.TYPE_HEADER_NAME_STRING: + return properties.getSubject(); + case MessageUtil.CONNECTION_ID_PROPERTY_NAME_STRING: + return getConnectionID(); + default: + return (String) getApplicationPropertiesMap(false).get(key); } }