mirror of https://github.com/apache/activemq.git
support options on MessageGroupMap types
This commit is contained in:
parent
59af7479b2
commit
cd4b229f22
|
@ -29,8 +29,12 @@ import org.apache.activemq.memory.LRUMap;
|
|||
*
|
||||
*/
|
||||
public class CachedMessageGroupMap implements MessageGroupMap {
|
||||
private LRUMap<String, ConsumerId> cache = new LRUMap<String, ConsumerId>(1024);
|
||||
|
||||
private final LRUMap<String, ConsumerId> cache;
|
||||
private final int maximumCacheSize;
|
||||
CachedMessageGroupMap(int size){
|
||||
cache = new LRUMap<String, ConsumerId>(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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* <a href="http://activemq.apache.org/message-groups.html">Message Groups</a> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String,String> 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);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,10 @@ public class MessageGroupHashBucket implements MessageGroupMap {
|
|||
return "bucket";
|
||||
}
|
||||
|
||||
public int getBucketCount(){
|
||||
return bucketCount;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
int count = 0;
|
||||
|
|
Loading…
Reference in New Issue