|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.ecp.internal.core.util.observer.ECPObserverBusImpl
public class ECPObserverBusImpl
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 the ECPObserver
interface, which is only used as a marker. Future use of
Annotations is possible.
by using notify(Class)
(e.g. bus.notify(MyObserver.class).myObserverMethod()
) all registered
Observers are notified.
This is implemented by using the java Proxy
class. By calling notify(Class)
a proxy is returned,
which then calls all registered observers.
The proxy can also be casted into ECPObserverCall
, 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
Constructor Summary | |
---|---|
ECPObserverBusImpl()
Default constructor. |
Method Summary | ||
---|---|---|
|
notify(Class<T> clazz)
This method allows you to notify all observers. |
|
|
notify(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,
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,
Class<? extends ECPObserver>... classes)
Unregisters an observer for the specified observer interfaces. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ECPObserverBusImpl()
Method Detail |
---|
public <T extends ECPObserver> T notify(Class<T> clazz)
notify
in interface ECPObserverBus
T
- class of observerclazz
- class of observer
public <T extends ECPObserver> T notify(Class<T> clazz, boolean prioritized)
T
- class of observerclazz
- class of observerprioritized
- sort observer after ECPPrioritizedIObserver
public void register(ECPObserver observer)
register
in interface ECPObserverBus
observer
- observer objectpublic void register(ECPObserver observer, Class<? extends ECPObserver>... classes)
observer
- observer objectclasses
- set of classespublic void unregister(ECPObserver observer)
unregister
in interface ECPObserverBus
observer
- observer objectpublic void unregister(ECPObserver observer, Class<? extends ECPObserver>... classes)
observer
- observer objectclasses
- set of classes
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |