1 package org.simantics.scl.compiler.module.repository;
3 import gnu.trove.set.hash.THashSet;
6 * Listener that is notified about changes in modules and their dependencies. It is possible
7 * to listen multiple different modules with one listener. When a change happens, the listener
8 * automatically stops listening any other changes. The idea is that the client then asks all modules
9 * again using the listener as a parameter.
11 public abstract class UpdateListener {
12 private final THashSet<Observable> observables = new THashSet<Observable>();
14 public interface Observable {
15 void removeListener(UpdateListener listener);
18 public abstract void notifyAboutUpdate();
21 * Registers an observable to the listener. The client code should never
22 * call this method. It is needed so that it is possible to implement
23 * {@link #stopListening}.
25 public void addObservable(Observable observable) {
26 synchronized(observables) {
27 observables.add(observable);
32 * Stops listening changes.
34 public void stopListening() {
35 synchronized(observables) {
36 for(Observable observable : observables)
37 observable.removeListener(this);