You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2018/05/24 12:44:39 UTC

qpid-broker-j git commit: QPID-7830: [Broker-J] Cache AMQP 1.0 application property names and message properties 'to' and 'subject'

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 830c31837 -> 85f1db6c4


QPID-7830: [Broker-J] Cache AMQP 1.0 application property names and message properties 'to' and 'subject'


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/85f1db6c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/85f1db6c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/85f1db6c

Branch: refs/heads/master
Commit: 85f1db6c4a2b5127ebec78cedcbe4563094cab47
Parents: 830c318
Author: Alex Rudyy <or...@apache.org>
Authored: Thu May 24 01:55:16 2018 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Thu May 24 13:44:00 2018 +0100

----------------------------------------------------------------------
 .../type/messaging/ApplicationProperties.java   |  6 ++-
 .../messaging/NonEncodingRetainingSection.java  | 30 +++++++++++
 .../v1_0/type/messaging/Properties.java         |  4 +-
 .../NonEncodingRetainingSectionTest.java        | 54 ++++++++++++++++++++
 4 files changed, 91 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/85f1db6c/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/ApplicationProperties.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/ApplicationProperties.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/ApplicationProperties.java
index 213c06b..f44f960 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/ApplicationProperties.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/ApplicationProperties.java
@@ -24,6 +24,7 @@
 package org.apache.qpid.server.protocol.v1_0.type.messaging;
 
 import java.util.Date;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
 
@@ -41,6 +42,7 @@ public class ApplicationProperties implements NonEncodingRetainingSection<Map<St
         {
             throw new IllegalArgumentException("Value must not be null");
         }
+        LinkedHashMap<String,Object> copy = new LinkedHashMap<>();
         for(Map.Entry<String,Object> entry: value.entrySet())
         {
             if (entry.getKey() == null)
@@ -51,8 +53,10 @@ public class ApplicationProperties implements NonEncodingRetainingSection<Map<St
             {
                 throw new IllegalArgumentException("Application properties do not allow non-primitive values");
             }
+
+            copy.put(NonEncodingRetainingSection.getCached(entry.getKey()), entry.getValue());
         }
-        _value = value;
+        _value = copy;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/85f1db6c/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSection.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSection.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSection.java
index fc9a43d..b6385c2 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSection.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSection.java
@@ -20,9 +20,39 @@
  */
 package org.apache.qpid.server.protocol.v1_0.type.messaging;
 
+import com.google.common.cache.Cache;
+
 import org.apache.qpid.server.protocol.v1_0.type.Section;
+import org.apache.qpid.server.virtualhost.CacheFactory;
+import org.apache.qpid.server.virtualhost.NullCache;
 
 public interface NonEncodingRetainingSection<T> extends Section<T>
 {
+    NullCache<String, String> NULL_CACHE = new NullCache<>();
+    ThreadLocal<Cache<String, String>> CACHE =
+            ThreadLocal.withInitial(() -> CacheFactory.getCache("stringCache", NULL_CACHE));
+
+    static Cache<String, String> getStringCache()
+    {
+        return CACHE.get();
+    }
+
+    /** Unit testing only */
+    static void setCache(final Cache<String, String> cache)
+    {
+        CACHE.set(cache);
+    }
+
+    static String getCached(final String value)
+    {
+        String cached = getStringCache().getIfPresent(value);
+        if (cached == null)
+        {
+            cached = value;
+            getStringCache().put(cached, cached);
+        }
+        return cached;
+    }
+
     EncodingRetainingSection<T> createEncodingRetainingSection();
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/85f1db6c/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/Properties.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/Properties.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/Properties.java
index 9c10cee..cb6c8b0 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/Properties.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/Properties.java
@@ -98,7 +98,7 @@ public class Properties implements NonEncodingRetainingSection<Properties>
 
     public void setTo(String to)
     {
-        _to = to;
+        _to = NonEncodingRetainingSection.getCached(to);
     }
 
     public String getSubject()
@@ -108,7 +108,7 @@ public class Properties implements NonEncodingRetainingSection<Properties>
 
     public void setSubject(String subject)
     {
-        _subject = subject;
+        _subject = NonEncodingRetainingSection.getCached(subject);
     }
 
     public String getReplyTo()

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/85f1db6c/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSectionTest.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSectionTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSectionTest.java
new file mode 100644
index 0000000..a56745a
--- /dev/null
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/messaging/NonEncodingRetainingSectionTest.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol.v1_0.type.messaging;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.junit.Test;
+
+public class NonEncodingRetainingSectionTest
+{
+
+    @Test
+    public void getCached()
+    {
+        Cache<String, String> original = NonEncodingRetainingSection.getStringCache();
+        Cache<String, String> cache = CacheBuilder.newBuilder().maximumSize(1).build();
+        NonEncodingRetainingSection.setCache(cache);
+
+        try
+        {
+            String string1 = NonEncodingRetainingSection.getCached(new String(new char[]{'t', 'e', 's', 't'}));
+            String string2 = NonEncodingRetainingSection.getCached(new String(new char[]{'t', 'e', 's', 't'}));
+
+            assertEquals(string1, string2);
+            assertSame(string1, string2);
+        }
+        finally
+        {
+            cache.cleanUp();
+            NonEncodingRetainingSection.setCache(original);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org