From 332cee8e663e729e2af274715cf0e1911a320297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Sun, 22 Jul 2018 04:17:50 +0100 Subject: [PATCH] ARTEMIS-1997 - un-needed SimpleString creation on hotpath with Filters Create the SimpleString on construction of PropertyExpression so it can be re-used instead of creating it every time its filtered in the FilterImpl --- artemis-selector/pom.xml | 5 +++++ .../activemq/artemis/selector/filter/Filterable.java | 4 +++- .../artemis/selector/filter/PropertyExpression.java | 12 +++++++++--- .../activemq/artemis/selector/SelectorTest.java | 10 ++++++---- .../artemis/core/filter/impl/FilterImpl.java | 10 +++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/artemis-selector/pom.xml b/artemis-selector/pom.xml index 1fc51b3c02..7d9b644ca6 100644 --- a/artemis-selector/pom.xml +++ b/artemis-selector/pom.xml @@ -32,6 +32,11 @@ + + org.apache.activemq + artemis-commons + ${project.version} + xml-apis xml-apis diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/Filterable.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/Filterable.java index 53396137d7..4ac7620ef9 100755 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/Filterable.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/Filterable.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.selector.filter; +import org.apache.activemq.artemis.api.core.SimpleString; + /** * A Filterable is the object being evaluated by the filters. It provides * access to filtered properties. @@ -41,7 +43,7 @@ public interface Filterable { * @param name * @return */ - Object getProperty(String name); + Object getProperty(SimpleString name); /** * Used by the NoLocal filter. diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/PropertyExpression.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/PropertyExpression.java index 4c8c8c502f..9fa62672bb 100755 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/PropertyExpression.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/PropertyExpression.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.selector.filter; +import org.apache.activemq.artemis.api.core.SimpleString; + /** * Represents a property expression * @@ -23,9 +25,13 @@ package org.apache.activemq.artemis.selector.filter; */ public class PropertyExpression implements Expression { - private final String name; + private final SimpleString name; public PropertyExpression(String name) { + this(SimpleString.toSimpleString(name)); + } + + public PropertyExpression(SimpleString name) { this.name = name; } @@ -35,7 +41,7 @@ public class PropertyExpression implements Expression { } public String getName() { - return name; + return name.toString(); } /** @@ -43,7 +49,7 @@ public class PropertyExpression implements Expression { */ @Override public String toString() { - return name; + return name.toString(); } /** diff --git a/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/SelectorTest.java b/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/SelectorTest.java index a540ed748b..1be9d475a2 100755 --- a/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/SelectorTest.java +++ b/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/SelectorTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.artemis.selector; import java.util.HashMap; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.selector.filter.BooleanExpression; import org.apache.activemq.artemis.selector.filter.FilterException; import org.apache.activemq.artemis.selector.filter.Filterable; @@ -100,14 +101,15 @@ public class SelectorTest { } @Override - public Object getProperty(String name) { - if ("JMSType".equals(name)) { + public Object getProperty(SimpleString name) { + String stringName = name.toString(); + if ("JMSType".equals(stringName)) { return type; } - if ("JMSMessageID".equals(name)) { + if ("JMSMessageID".equals(stringName)) { return messageId; } - return properties.get(name); + return properties.get(stringName); } public Object getDestination() { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java index 33a11870fd..7ee7b6bf81 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java @@ -154,7 +154,7 @@ public class FilterImpl implements Filter { // Proton stores JMSMessageID as NATIVE_MESSAGE_ID that is an arbitrary string String amqpNativeID = msg.getStringProperty(NATIVE_MESSAGE_ID); if (amqpNativeID != null) { - return new SimpleString(amqpNativeID); + return SimpleString.toSimpleString(amqpNativeID); } } // It's the stringified (hex) representation of a user id that can be used in a selector expression @@ -162,7 +162,7 @@ public class FilterImpl implements Filter { if (userID.startsWith("ID:")) { return SimpleString.toSimpleString(userID); } else { - return new SimpleString("ID:" + msg.getUserID()); + return SimpleString.toSimpleString("ID:" + msg.getUserID()); } } else if (FilterConstants.ACTIVEMQ_PRIORITY.equals(fieldName)) { return Integer.valueOf(msg.getPriority()); @@ -190,10 +190,10 @@ public class FilterImpl implements Filter { } @Override - public Object getProperty(String id) { + public Object getProperty(SimpleString id) { Object result = null; - if (id.startsWith(FilterConstants.ACTIVEMQ_PREFIX.toString())) { - result = getHeaderFieldValue(message, new SimpleString(id)); + if (id.startsWith(FilterConstants.ACTIVEMQ_PREFIX)) { + result = getHeaderFieldValue(message, id); } if (result == null) { result = message.getObjectProperty(id);