KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jms > connector > JMSDestinations


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.jms.connector;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10 import javax.jms.Destination JavaDoc;
11
12 /**
13  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
14  */

15
16 public class JMSDestinations {
17
18 // private List<Destination> destinations = new ArrayList<Destination>();
19

20     private Map JavaDoc<Destination JavaDoc, List JavaDoc<ConsumerMeta>> destinations = new HashMap JavaDoc<Destination JavaDoc, List JavaDoc<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     /**
32      * register a new destination
33      */

34     public void registerDestination(Destination JavaDoc destination) {
35         destinations.put(destination, new ArrayList JavaDoc<ConsumerMeta>());
36     }
37
38     //TODO: session.close 的时候,要 unregister 该 Session 创建的Destination
39
public void unregisterDestination(Destination JavaDoc destination) {
40         destinations.remove(destination);
41     }
42
43     public boolean isDestinationRegistered(Destination JavaDoc destination) {
44         return destinations.containsKey(destination);
45     }
46
47     public void registerConsumer(Destination JavaDoc destination, ConsumerMeta consumerMeta) {
48         if (!isDestinationRegistered(destination)) {
49             List JavaDoc<ConsumerMeta> metas = new ArrayList JavaDoc<ConsumerMeta>();
50             metas.add(consumerMeta);
51             destinations.put(destination, metas);
52         } else {
53             List JavaDoc<ConsumerMeta> metas = getConsumerMetas(destination);
54             metas.add(consumerMeta);
55         }
56     }
57
58     public List JavaDoc<ConsumerMeta> getConsumerMetas(Destination JavaDoc destination) {
59         if (!isDestinationRegistered(destination)) {
60             return new ArrayList JavaDoc<ConsumerMeta>();
61         } else {
62             return destinations.get(destination);
63         }
64     }
65
66     public boolean hashConsumer(Destination JavaDoc destination) {
67         return !destinations.get(destination).isEmpty();
68     }
69
70     public static void main(String JavaDoc[] args) {
71
72     }
73 }
74
75
Popular Tags