View Javadoc

1   package org.lsst.ccs.utilities.dispatch;
2   
3   /**
4    * This interface defines the behaviour of a class implementing a Command pattern.
5    * <P>
6    * Example:
7    * <UL>
8    *     Lets define a class <TT>Doer</TT> that has a method <TT>show(String string, int anInt)</TT>.
9    *     When do we need to send a "command" to such an Object instead of just calling directly this method?
10   *     It could be that the code that "relays" this invocation does not know much about the sender , the receiver
11   *     and the method itself.
12   *     <BR>
13   *      for instance  we may want to send a "command" to such an Object through the wire and invoke the method across
14   *      the network (without predefined RMI) or we have a generic code that dispatches a call to many receivers.
15   *      <BR>
16   *      In programming parlance we are going to "<I>reify</I>" the method call: that is transform it into an Object.
17   *      <BR>
18   *      So the object representing this method call and implementing the Command could look like that:
19   *      <PRE>
20   *          class ShowCommand implements CommandFor<Doer> , Serializable{
21   *              String arg1 ;
22   *              int arg2 ;
23   *              // constructor and everything
24   *              public void invokeOn(Doer someInstance) {
25   *                  someInstance.show(arg1, arg2)
26   *              }
27   *          }
28   *      </PRE>
29   *      Now suppose the receiving code reads the command from a Stream
30   *      <PRE>
31   *          Doer actor ; // initialized
32   *          // then later
33   *          ShowCommand command = (ShowCommand) objectStream.readObject() ;
34   *          command.invokeOn(actor); // and that's it!
35   *      </PRE>
36   * </UL>
37   *@see org.lsst.ccs.utilities.dispatch.SynchronousCommandFor
38   *@see org.lsst.ccs.utilities.dispatch.SynchronousCommandDispatcher
39   *@see org.lsst.ccs.utilities.dispatch.ParallelCommandDispatcher
40   *
41   *@author bernard Amade
42   */
43  public interface CommandFor<T> {
44      public  void invokeOn(T instance);
45  }