summaryrefslogtreecommitdiff
path: root/java/common/src
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2013-05-23 22:27:03 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2013-05-23 22:27:03 +0000
commit9e8535fb05da0640a93791ddf8328a12773280e4 (patch)
treee6d382486264a0e2d98a4e191b6fbe81d432ff96 /java/common/src
parenta4a3e238cf1dbfbea386fc886bf92df06200e034 (diff)
downloadqpid-python-9e8535fb05da0640a93791ddf8328a12773280e4.tar.gz
QPID-4873 Commiting patch by Helen Kwong.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1485878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/src')
-rw-r--r--java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java46
-rw-r--r--java/common/src/main/java/org/apache/qpid/messaging/util/Parser.java14
3 files changed, 57 insertions, 5 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
index 7aa280ce02..a0140785f4 100644
--- a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
@@ -205,6 +205,8 @@ public class ClientProperties
public static final String QPID_DECLARE_EXCHANGES_PROP_NAME = "qpid.declare_exchanges";
public static final String VERIFY_QUEUE_ON_SEND = "qpid.verify_queue_on_send";
+ public static final String QPID_MAX_CACHED_ADDR_OPTION_STRINGS = "qpid.max_cached_address_option_strings";
+ public static final int DEFAULT_MAX_CACHED_ADDR_OPTION_STRINGS = 10;
private ClientProperties()
{
diff --git a/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java b/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java
index d1e10607ac..4e3782673c 100644
--- a/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java
+++ b/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java
@@ -20,12 +20,17 @@
*/
package org.apache.qpid.messaging.util;
-import org.apache.qpid.messaging.Address;
-
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.messaging.Address;
/**
@@ -58,6 +63,23 @@ public class AddressParser extends Parser
private static Lexer LEXER = lxi.compile();
+ private static final int MAX_CACHED_ENTRIES = Integer.getInteger(ClientProperties.QPID_MAX_CACHED_ADDR_OPTION_STRINGS,
+ ClientProperties.DEFAULT_MAX_CACHED_ADDR_OPTION_STRINGS);
+
+ // stores address options maps for options strings that we have encountered; using a synchronizedMap wrapper
+ // in case multiple threads are parsing addresses.
+ private static Map<String, Map<Object, Object>> optionsMaps =
+ Collections.synchronizedMap(
+ new LinkedHashMap<String, Map<Object, Object>>(MAX_CACHED_ENTRIES +1,1.1f,true)
+ {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<String,Map<Object, Object>> eldest)
+ {
+ return size() > MAX_CACHED_ENTRIES;
+ }
+
+ });
+
public static List<Token> lex(String input)
{
return LEXER.lex(input);
@@ -267,11 +289,27 @@ public class AddressParser extends Parser
subject = null;
}
- Map options;
+ Map<Object, Object> options;
if (matches(SEMI))
{
eat(SEMI);
- options = map();
+
+ // get the remaining string denoting the options and see if we've already encountered an address
+ // with the same options before
+ String optionsString = toks2str(remainder());
+ Map<Object,Object> storedMap = optionsMaps.get(optionsString);
+ if (storedMap == null)
+ {
+ // if these are new options, construct a new map and store it in the encountered collection
+ options = Collections.unmodifiableMap(map());
+ optionsMaps.put(optionsString, options);
+ }
+ else
+ {
+ // if we already have the map for these options, use the stored map
+ options = storedMap;
+ eat_until(EOF);
+ }
}
else
{
diff --git a/java/common/src/main/java/org/apache/qpid/messaging/util/Parser.java b/java/common/src/main/java/org/apache/qpid/messaging/util/Parser.java
index 2e983f5165..3019326963 100644
--- a/java/common/src/main/java/org/apache/qpid/messaging/util/Parser.java
+++ b/java/common/src/main/java/org/apache/qpid/messaging/util/Parser.java
@@ -74,7 +74,7 @@ class Parser
List<Token> eat_until(Token.Type ... types)
{
- List<Token> result = new ArrayList();
+ List<Token> result = new ArrayList<Token>();
while (!matches(types))
{
result.add(eat());
@@ -82,4 +82,16 @@ class Parser
return result;
}
+ /**
+ * Returns the remaining list of tokens, without eating them
+ */
+ List<Token> remainder()
+ {
+ List<Token> result = new ArrayList<Token>();
+ for (int i = idx; i < tokens.size(); i++)
+ {
+ result.add(tokens.get(i));
+ }
+ return result;
+ }
}