From cd4b229f222d96c76753249baa323d0a2c89f287 Mon Sep 17 00:00:00 2001 From: rajdavies Date: Fri, 11 Oct 2013 11:07:20 +0100 Subject: [PATCH] support options on MessageGroupMap types --- .../region/group/CachedMessageGroupMap.java | 12 ++++++++++-- .../group/CachedMessageGroupMapFactory.java | 14 ++++++++++++-- .../region/group/GroupFactoryFinder.java | 18 +++++++++++++++++- .../region/group/MessageGroupHashBucket.java | 4 ++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMap.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMap.java index 7829ec4f63..084e8d05db 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMap.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMap.java @@ -29,8 +29,12 @@ import org.apache.activemq.memory.LRUMap; * */ public class CachedMessageGroupMap implements MessageGroupMap { - private LRUMap cache = new LRUMap(1024); - + private final LRUMap cache; + private final int maximumCacheSize; + CachedMessageGroupMap(int size){ + cache = new LRUMap(size); + maximumCacheSize = size; + } public synchronized void put(String groupId, ConsumerId consumerId) { cache.put(groupId, consumerId); } @@ -80,6 +84,10 @@ public class CachedMessageGroupMap implements MessageGroupMap { return "cached"; } + public int getMaximumCacheSize(){ + return maximumCacheSize; + } + public String toString() { return "message groups: " + cache.size(); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMapFactory.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMapFactory.java index 7387c5a1d8..b0a0be8ee7 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMapFactory.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/CachedMessageGroupMapFactory.java @@ -17,7 +17,7 @@ package org.apache.activemq.broker.region.group; /** - * A factory to create instances of {@link org.apache.activemq.broker.region.group.SimpleMessageGroupMap} when implementing the + * A factory to create instances of {@link org.apache.activemq.broker.region.group.CachedMessageGroupMap} when implementing the * Message Groups functionality. * * @org.apache.xbean.XBean @@ -26,8 +26,18 @@ package org.apache.activemq.broker.region.group; */ public class CachedMessageGroupMapFactory implements MessageGroupMapFactory { + private int cacheSize = 1024; + public int getCacheSize() { + return cacheSize; + } + + public void setCacheSize(int cacheSize) { + this.cacheSize = cacheSize; + } + + public MessageGroupMap createMessageGroupMap() { - return new CachedMessageGroupMap(); + return new CachedMessageGroupMap(getCacheSize()); } } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/GroupFactoryFinder.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/GroupFactoryFinder.java index 168804ff8b..718b37d708 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/GroupFactoryFinder.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/GroupFactoryFinder.java @@ -17,9 +17,12 @@ package org.apache.activemq.broker.region.group; import java.io.IOException; +import java.util.Map; import org.apache.activemq.util.FactoryFinder; import org.apache.activemq.util.IOExceptionSupport; +import org.apache.activemq.util.IntrospectionSupport; +import org.apache.activemq.util.URISupport; public class GroupFactoryFinder { private static final FactoryFinder GROUP_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/groups/"); @@ -29,7 +32,20 @@ public class GroupFactoryFinder { public static MessageGroupMapFactory createMessageGroupMapFactory(String type) throws IOException { try { - return (MessageGroupMapFactory)GROUP_FACTORY_FINDER.newInstance(type); + Map properties = null; + String factoryType = type.trim(); + int p = factoryType.indexOf('?'); + if (p >= 0){ + String propertiesString = factoryType.substring(p+1); + factoryType = factoryType.substring(0,p); + properties = URISupport.parseQuery(propertiesString); + } + MessageGroupMapFactory result = (MessageGroupMapFactory)GROUP_FACTORY_FINDER.newInstance(factoryType); + if (properties != null && result != null){ + IntrospectionSupport.setProperties(result,properties); + } + return result; + } catch (Throwable e) { throw IOExceptionSupport.create("Could not load " + type + " factory:" + e, e); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/MessageGroupHashBucket.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/MessageGroupHashBucket.java index c36f949dcc..a18e4d20f9 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/MessageGroupHashBucket.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/group/MessageGroupHashBucket.java @@ -92,6 +92,10 @@ public class MessageGroupHashBucket implements MessageGroupMap { return "bucket"; } + public int getBucketCount(){ + return bucketCount; + } + public String toString() { int count = 0;