Package net.sf.taverna.t2.lang.observer

Implementation of the observer pattern.

See:
          Description

Interface Summary
Observable<Message> Implements this if you want to notify other classes about changes
Observer<Message> Implement if you want to register with an Observable
 

Class Summary
MultiCaster<Message> Send notifications to registered observers about changes to models
ObserverTest  
 

Package net.sf.taverna.t2.lang.observer Description

Implementation of the observer pattern. Observers registers with an Observable using Observable#addObserver(Observer), and will receive notifications as a call to Observer#notify(Observable, Object).

Typical implementations of Observable will be delegating to a MultiCaster to do the boring observer registration and message dispatching.

Example of Observable:

 public class MyObservable implements Observable {
         public static class MyEvent {
                // ..
         }
         private MultiCaster<:MyEvent> multiCaster = new MultiCaster<:MyEvent>(this);
 
         public void doStuff() {
                multiCaster.notify(new MyEvent());
         }
 
         public void addObserver(Observer observer) {
                multiCaster.addObserver(observer);
         }
 
         public List> getObservers() {
                return multiCaster.getObservers();
         }
 
         public void removeObserver(Observer observer) {
                multiCaster.removeObserver(observer);
         }
 }
 
And an observer that is notified when MyObservable.doStuff() is called:
 public class MyObserver implements Observer {
         public void notify(Observable sender, MyEvent message) {
                System.out.println("Receieved " + message + " from " + sender);
         }
 }
 
Example of usage:
                MyObservable observable = new MyObservable();
                MyObserver observer = new MyObserver();
                observable.addObserver(observer);
                observable.doStuff();