View Javadoc

1   package org.lsst.ccs.utilities.dispatch;
2   
3   
4   import java.util.concurrent.CopyOnWriteArrayList;
5   
6   /**
7    * An <TT>Observable</TT> with protocol control at compile time.
8    * The update are processed in sequence.
9    *
10   * @author bernard Amade
11   */
12  public class SynchronousObservable<P> {
13      protected CopyOnWriteArrayList<SynchronousObserver<P>> list = new java.util.concurrent.CopyOnWriteArrayList<SynchronousObserver<P>>() ;
14  
15      public void addObserver(SynchronousObserver<P> observer){
16          this.list.add(observer);
17      }
18  
19      public void removeObserver(SynchronousObserver<P> observer){
20          this.list.remove (observer);
21      }
22  
23      /**
24       * do not need a call to <TT>setChanged</TT>: observers
25       * are immediately notified.
26       *
27       * @param protocol
28       */
29      public void notifyObservers(P protocol) {
30          for(SynchronousObserver<P> observer : list) {
31              observer.update(protocol);
32          }
33      }
34  }