LSST CCS Software

Welcome to the main page of the LSST CCS Software.

org-lsst-ccs-utilities

package "org.lsst.ccs.utilities.dispatch"

The Observer/observable pattern may come in different flavors offered by this package.

Primarily there are two main concerns addressed in the codes of this package:

  • Control over the parameter passed to method notifyObservers and received by update : this control is through the use of a parameterized type. At compile-time we can now check what is sent and what is received (named here the "protocol").
  • Explicit specification of the nature of code dispatching: "synchronous" means that the update codes of the Observer are executed in sequence and that the implementers are conscious that thus their code should terminate quickly; "parallel" means that the update codes are executed by different Threads. In both cases the nature of the update method is procedural (no return type) and exceptions are logged (they should not crash the system).

    TODO: change the logging to log4j

So the "traditional" Observer/Observable pair can be replaced by SynchronousObserver and SynchronousObservable. The main differences are:

  • method update takes no reference to the Observable (if you need one: create an Event-like protocol that has a reference to the sender).
  • method notifyObservers does not need a previous call to setChanged

If parallel processing is needed use instead ASyncObserver and ParallelObservable .

Now why limit notifications to a single method? We may go through different methods....

So there are two different patterns in this package to handle calls to different methods for the registered agents:

  • Use of a Command pattern: see interfaces CommandFor, SynchronousCommandFor and Observable-like classes SynchronousCommandDispatcher, ParallelCommandDispatcher
  • Use of a Proxy: in that case the Observer classes should implement an interface class that is passed to a proxy generator (SynchronousDispatchProxy or ParallelDispatchProxy).

    These classes generate a very special object implementing the requested interface: a call to a method of this object is automatically forwarded to all the registered agents that implement the same interface.