1 4 package org.jfox.jms.connector; 5 6 import java.util.ArrayList ; 7 import java.util.HashMap ; 8 import java.util.List ; 9 import java.util.Map ; 10 import javax.jms.Destination ; 11 12 15 16 public class JMSDestinations { 17 18 20 private Map <Destination , List <ConsumerMeta>> destinations = new HashMap <Destination , List <ConsumerMeta>>(); 21 22 private final static JMSDestinations me = new JMSDestinations(); 23 24 private JMSDestinations() { 25 } 26 27 public static JMSDestinations getInstance() { 28 return me; 29 } 30 31 34 public void registerDestination(Destination destination) { 35 destinations.put(destination, new ArrayList <ConsumerMeta>()); 36 } 37 38 public void unregisterDestination(Destination destination) { 40 destinations.remove(destination); 41 } 42 43 public boolean isDestinationRegistered(Destination destination) { 44 return destinations.containsKey(destination); 45 } 46 47 public void registerConsumer(Destination destination, ConsumerMeta consumerMeta) { 48 if (!isDestinationRegistered(destination)) { 49 List <ConsumerMeta> metas = new ArrayList <ConsumerMeta>(); 50 metas.add(consumerMeta); 51 destinations.put(destination, metas); 52 } else { 53 List <ConsumerMeta> metas = getConsumerMetas(destination); 54 metas.add(consumerMeta); 55 } 56 } 57 58 public List <ConsumerMeta> getConsumerMetas(Destination destination) { 59 if (!isDestinationRegistered(destination)) { 60 return new ArrayList <ConsumerMeta>(); 61 } else { 62 return destinations.get(destination); 63 } 64 } 65 66 public boolean hashConsumer(Destination destination) { 67 return !destinations.get(destination).isEmpty(); 68 } 69 70 public static void main(String [] args) { 71 72 } 73 } 74 75 | Popular Tags |