Class ECPObserverBusImpl
- java.lang.Object
-
- org.eclipse.emf.ecp.internal.core.util.observer.ECPObserverBusImpl
-
- All Implemented Interfaces:
ECPObserverBus
public class ECPObserverBusImpl extends java.lang.Object implements ECPObserverBus
This is a universal observer bus. This class follows the publish/subscribe pattern, it is a central dispatcher for observers and makes use of generics in order to allow type safety. It can be used as singleton or be injected through DI. Observers have to implement theECPObserver
interface, which is only used as a marker. Future use of Annotations is possible. by usingnotify(Class)
(e.g.bus.notify(MyObserver.class).myObserverMethod()
) all registered Observers are notified. This is implemented by using the javaProxy
class. By callingnotify(Class)
a proxy is returned, which then calls all registered observers. The proxy can also be casted intoECPObserverCall
, which allows to access all results by the different observers. Example code:// A is ESObserver A a = new A() { public void foo() { System.out.println("A says: go!"); } }; // B extends A and is IObserver B b = new B() { public void say(String ja) { System.out.println("B says: " + ja); } public void foo() { System.out.println("B says: h??"); } }; // B is registered first ObserverBus.register(b); ObserverBus.register(a); ObserverBus.notify(A.class).foo(); ObserverBus.notify(B.class).say("w00t"); // Output: // B says: h?? // A says: go! // // B says: w00t
- Author:
- wesendon
-
-
Constructor Summary
Constructors Constructor Description ECPObserverBusImpl()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends ECPObserver>
Tnotify(java.lang.Class<T> clazz)
This method allows you to notify all observers.<T extends ECPObserver>
Tnotify(java.lang.Class<T> clazz, boolean prioritized)
This method allows you to notify all observers.void
register(ECPObserver observer)
Registers an observer for all observer interfaces implemented by the object or its super classes.void
register(ECPObserver observer, java.lang.Class<? extends ECPObserver>... classes)
Registers an observer for the specified observer interfaces.void
unregister(ECPObserver observer)
Unregisters an observer for all observer interfaces implemented by the object or its super classes.void
unregister(ECPObserver observer, java.lang.Class<? extends ECPObserver>... classes)
Unregisters an observer for the specified observer interfaces.
-
-
-
Method Detail
-
notify
public <T extends ECPObserver> T notify(java.lang.Class<T> clazz)
This method allows you to notify all observers.- Specified by:
notify
in interfaceECPObserverBus
- Type Parameters:
T
- class of observer- Parameters:
clazz
- class of observer- Returns:
- call object
-
notify
public <T extends ECPObserver> T notify(java.lang.Class<T> clazz, boolean prioritized)
This method allows you to notify all observers.- Type Parameters:
T
- class of observer- Parameters:
clazz
- class of observerprioritized
- sort observer afterECPPrioritizedIObserver
- Returns:
- call object
-
register
public void register(ECPObserver observer)
Registers an observer for all observer interfaces implemented by the object or its super classes.- Specified by:
register
in interfaceECPObserverBus
- Parameters:
observer
- observer object
-
register
public void register(ECPObserver observer, java.lang.Class<? extends ECPObserver>... classes)
Registers an observer for the specified observer interfaces.- Parameters:
observer
- observer objectclasses
- set of classes
-
unregister
public void unregister(ECPObserver observer)
Unregisters an observer for all observer interfaces implemented by the object or its super classes.- Specified by:
unregister
in interfaceECPObserverBus
- Parameters:
observer
- observer object
-
unregister
public void unregister(ECPObserver observer, java.lang.Class<? extends ECPObserver>... classes)
Unregisters an observer for the specified observer interfaces.- Parameters:
observer
- observer objectclasses
- set of classes
-
-