View Javadoc

1   package org.lsst.ccs.bus;
2   
3   import org.lsst.ccs.utilities.logging.Logger;
4   
5   import java.io.Serializable;
6   import java.util.Arrays;
7   
8   /**
9    * A command sent on the CCS bus.
10   * <p/>
11   * Will be executed by the destination subsystem.
12   *
13   * @author Eric Aubourg
14   */
15  public abstract class Command extends BusMessage implements CommandBusMessage {
16  
17      /**
18       * to be used by subclasses for no args for commands
19       */
20      public static final Serializable[] NO_ARGS = new Serializable[0];
21      private static final long serialVersionUID = 1488098756706412158L;
22      protected static final Logger log = Logger.getLogger("org.lsst.ccs.bus.Command");
23  
24      @Override
25      public String getMessageType() {
26          return "lsst.command";
27      }
28  
29      /* targeting */
30      //@NotNull
31      protected String destination = "*";
32      //@NotNull (when lock manage is active)
33      protected String key;
34      /** The level of the <b>sender</b> of this command. */
35      protected int level;
36      /**
37       * Correlation id, propagated from command to command
38       */
39      //@NotNull
40      String correlId;
41      // @NotNull (see  specific subclasses)
42      protected String command;
43      protected Object[] parameters = NO_ARGS;
44      /**
45       * Indicates that the command is a pure String to be parsed by the receiver.
46       * In this case no arguments should be specified.
47       */
48      protected boolean unParsed = false;
49  
50      // from BusMessage : lacks origin, summary, priorityLevel, detailLevel
51      // lacks  correlID, unparsed
52      protected Command(String key, int level, String destination, String command, Object... parameterz) {
53          this.level = level;
54          this.destination = destination;
55          this.command = command;
56          this.parameters = parameterz;
57      }
58  
59      /**
60       * The command destination : subsystem name
61       *
62       * @return command destination
63       */
64      public String getDestination() {
65          return destination;
66      }
67  
68      /**
69       * The command destination : subsystem name
70       *
71       * @param destination
72       */
73      public void setDestination(String destination) {
74          this.destination = destination;
75      }
76  
77      /* locking and arbitrating */
78      /**
79       * Key used for lock and arbitration. If set, incoming commands must have
80       * the same key.
81       *
82       * @return the key
83       */
84      public String getKey() {
85          return key;
86      }
87  
88      /**
89       * Key used for lock and arbitration. If set, incoming commands must have
90       * the same key
91       *
92       * @param key
93       */
94      public void setKey(String key) {
95          this.key = key;
96      }
97  
98      /**
99       * is this command a writing command that has to be protected ?
100      * <BR/>
101      * <B>Deprecated</B> this is defined in the Command annotation
102      */
103     @Deprecated
104     public boolean isWrite() {
105         return true;
106     }
107 
108     /* can this command wait for a single-threaded ownerSubsystem to be ready */
109     /**
110      * <B>Deprecated</B> this is subject to re-evaluation of specs
111      */
112     @Deprecated
113     protected boolean canWaitForReady = true;
114 
115     /**
116      * can this command wait for a single-threaded ownerSubsystem to be ready ?
117      *
118      * @return a boolean
119      */
120     @Deprecated
121     public boolean canWaitForReady() {
122         return canWaitForReady;
123     }
124 
125     /**
126      * can this command wait for a single-threaded ownerSubsystem to be ready
127      *
128      * @param canWaitForReady
129      */
130     @Deprecated
131     public void setCanWaitForReady(boolean canWaitForReady) {
132         this.canWaitForReady = canWaitForReady;
133     }
134 
135     /**
136      * <B>Deprecated</B> this is defined in the Command annotation
137      */
138     @Deprecated
139     protected boolean canRunInActiveMode = true;
140 
141     /**
142      * Can this command be executed by a subsystem which is in "active" mode ?
143      *
144      * @return a boolean
145      */
146     @Deprecated
147     public boolean canRunInActiveMode() {
148         return canRunInActiveMode;
149     }
150 
151     @Deprecated
152     public void setCanRunInActiveMode(boolean canRunInActiveMode) {
153         this.canRunInActiveMode = canRunInActiveMode;
154     }
155 
156     @Override
157     public String toString() {
158         return getClass().getName() + " from " + origin + " to " + destination + "["
159                 + this.getCommand() + "(" + Arrays.toString(parameters) + ")";
160     }
161 
162     public String getCorrelId() {
163         return correlId;
164     }
165 
166     /**
167      * Correlation id, propagated from command to command. Users of this class
168      * can set a specific correlation id, but otherwise one will be generated
169      * automatically.
170      */
171     public void setCorrelId(String correlId) {
172         this.correlId = correlId;
173     }
174 
175     //TODO : 2 subclasses ...
176     public boolean isUnParsed() {
177         return unParsed;
178     }
179 
180     public void setUnParsed(boolean unParsed) {
181         this.unParsed = unParsed;
182     }
183 
184     public String getCommand() {
185         return command;
186     }
187 
188     public Object[] getParameters() {
189         return parameters;
190     }
191 
192     public int getLevel() {
193         return level;
194     }
195 
196     @Deprecated
197     public void setLevel(int level) {
198         this.level = level;
199     }
200 }