View Javadoc

1   package org.lsst.ccs.bus.jgroups;
2   
3   import org.jgroups.*;
4   
5   import java.util.HashMap;
6   import java.util.Map;
7   
8   /**
9    * @author bamade
10   */
11  @Deprecated
12  public class GroupTopic {
13      static Map<String,GroupTopic> map = new HashMap<String, GroupTopic>();
14  
15      private String topicName ;
16      private JChannel channel ;
17      private ReceiverAdapter adapter ;
18  
19      private GroupTopic(String topicName, String stackProperties) throws Exception {
20          this.topicName = topicName;
21          //this.adapter = adapter;
22          this.channel = new JChannel(stackProperties) ;
23          this.channel.connect(topicName);
24          //this.channel.setReceiver(adapter);
25      }
26  
27  
28      public String getTopicName() {
29          return topicName;
30      }
31  
32      public JChannel getChannel() {
33          return channel;
34      }
35  
36      public ReceiverAdapter getAdapter() {
37          return adapter;
38      }
39  
40      public void setAdapter(ReceiverAdapter adapter) {
41          this.adapter= adapter ;
42          this.channel.setReceiver(adapter);
43      }
44  
45      /**
46       * Call only once for a topic otherwise else receiver argument will not be accoutned for!
47       */
48      public static synchronized GroupTopic create(String topic, String stackProperties) throws Exception {
49          GroupTopic res = map.get(topic);
50          if( res == null) {
51              res = new GroupTopic(topic, stackProperties) ;
52              map.put(topic, res);
53          }
54          return res ;
55      }
56      // TODO: make it AutoCloseable
57      public void close() {
58          this.channel.close();
59      }
60  
61      public static synchronized void closeAll() {
62          for(GroupTopic top : map.values()){
63              top.close() ;
64          }
65  
66      }
67  
68      public void sendMessage(Object obj) throws Exception {
69          this.channel.send(new Message(null, null, obj));
70      }
71  }