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 16:24:41 UTC
[3/4] qpid-broker-j git commit: QPID-7830: [Broker-J] Cache AMQP 1.0
application property names and message properties 'to' and 'subject'
QPID-7830: [Broker-J] Cache AMQP 1.0 application property names and message properties 'to' and 'subject'
(cherry picked from commit 85f1db6c4a2b5127ebec78cedcbe4563094cab47)
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/c14eb33b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/c14eb33b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/c14eb33b
Branch: refs/heads/7.0.x
Commit: c14eb33b5062b81e9475215fc0f90b21026b4eae
Parents: 28e73f3
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 16:46:50 2018 +0100
----------------------------------------------------------------------
.../type/messaging/ApplicationProperties.java | 6 ++-
.../messaging/NonEncodingRetainingSection.java | 30 ++++++++++++
.../v1_0/type/messaging/Properties.java | 4 +-
.../NonEncodingRetainingSectionTest.java | 50 ++++++++++++++++++++
4 files changed, 87 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c14eb33b/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/c14eb33b/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/c14eb33b/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/c14eb33b/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..5ec08ab
--- /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,50 @@
+/*
+ *
+ * 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 com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class NonEncodingRetainingSectionTest extends QpidTestCase
+{
+ public void testGetCached()
+ {
+ 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