1 18 package org.apache.activemq.broker.region.group; 19 20 import java.util.concurrent.ConcurrentHashMap ; 21 22 import org.apache.activemq.command.ConsumerId; 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 34 public class SimpleMessageGroupMap implements MessageGroupMap { 35 private Map map = new ConcurrentHashMap (); 36 37 public void put(String groupId, ConsumerId consumerId) { 38 map.put(groupId, consumerId); 39 } 40 41 public ConsumerId get(String groupId) { 42 return (ConsumerId) map.get(groupId); 43 } 44 45 public ConsumerId removeGroup(String groupId) { 46 return (ConsumerId) map.remove(groupId); 47 } 48 49 public MessageGroupSet removeConsumer(ConsumerId consumerId) { 50 SimpleMessageGroupSet ownedGroups = new SimpleMessageGroupSet(); 51 for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { 52 String group = (String ) iter.next(); 53 ConsumerId owner = (ConsumerId) map.get(group); 54 if (owner.equals(consumerId)) { 55 ownedGroups.add(group); 56 iter.remove(); 57 } 58 } 59 return ownedGroups; 60 } 61 62 public String toString() { 63 return "message groups: " + map.size(); 64 } 65 66 } 67 | Popular Tags |