View Javadoc

1   package org.lsst.ccs.bus;
2   
3   import org.lsst.ccs.bootstrap.resources.BootstrapResourceUtils;
4   
5   import java.util.Collections;
6   import java.util.List;
7   
8   /**
9    * Messaging factory, insulating the application from the messaging middleware
10   * (JMS or other)
11   *
12   * @author aubourg
13   */
14  
15  public abstract class MessagingFactory {
16      protected volatile static MessagingFactory instance;
17  
18      //@TODO: should be getInstance( String subsystemName)
19      public static synchronized MessagingFactory getInstance() {
20          if (instance == null) {
21              instanciate();
22          }
23          return instance;
24      }
25  
26      protected static void instanciate() {
27          String clazz = BootstrapResourceUtils.getBootstrapSystemProperties().getProperty("org.lsst.ccs.messaging.factory", "org.lsst.ccs.bus.BusMessagingFactory");
28          try {
29              instance = (MessagingFactory) Class.forName(clazz).newInstance();
30          } catch (InstantiationException e) {
31              throw new RuntimeException(e);
32          } catch (IllegalAccessException e) {
33              throw new RuntimeException(e);
34          } catch (ClassNotFoundException e) {
35              throw new RuntimeException(e);
36          } catch (Exception e) { //@modified (bamade) : for other crashes
37              throw new RuntimeException(e);
38          }
39      }
40      
41      //todo: change that (added by bamade)
42      
43      private String subsystemName;
44  
45      public  MessagingFactory forSubsystem(String subsystemName) {
46  	this.subsystemName=subsystemName;
47          return this ;
48      }
49  
50      public String getSubsystemName() {
51  	return subsystemName;
52      }
53  
54      public abstract void addCommandListener(CommandListener l);
55      public abstract void removeCommandListener(CommandListener l);
56  
57      public abstract void addStatusListener(StatusListens l);
58      public abstract void removeStatusListener(StatusListens l);
59  
60      public abstract void addLogListener(LogListener l);
61      public abstract void removeLogListener(LogListener l);
62  
63      public abstract void addCommandListener(CommandListener l, String selector);
64      public abstract void addStatusListener(StatusListens l, String selector);
65      public abstract void addLogListener(LogListener l, String selector);
66      
67      public abstract void addMembershipListener(BusMembershipListener l);
68      public abstract void removeMembershipListener(BusMembershipListener l);
69  
70      public abstract void sendCommand(Command cmd);
71  
72      // TODO sendCommandSync qui retourne un Reply
73  
74      public abstract void sendStatus(Status status);
75  
76      public abstract void sendLogEvent(LogEvent evt);
77  
78      public abstract String getToken();
79  
80      /* has to be called on the same thread as the command */
81      public abstract void reply(CommandAckOrReply cmd);
82  
83      public boolean isReplyRequested() {
84          return false;
85      }
86  
87      public abstract void noAutoReply();
88      //@modified (bamade) -> @TODO: add a close() method to stop listening threads!
89      public void shutdownBusAccess() {
90  
91      }
92      public List<String> connectedToCommand() {
93          return Collections.EMPTY_LIST ;
94      }
95  
96  }