public interface ECPObserverBus
ECPObserver
to
discover possible types.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.
// A is ECPObserver A a = new A() { public void foo() { System.out.println("A says: go!"); } }; // B extends A and is ECPObserver 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 ECPObserverBus.register(b); ECPObserverBus.register(a); ECPObserverBus.notify(A.class).foo(); ECPObserverBus.notify(B.class).say("w00t"); // Output: // B says: h?? // A says: go! // // B says: w00t
Modifier and Type | Method and Description |
---|---|
<T extends ECPObserver> |
notify(Class<T> clazz)
This method allows you to notify all observers of type
|
void |
register(ECPObserver observer)
Registers an observer for all observer interfaces implemented by the object or its super classes.
|
void |
unregister(ECPObserver observer)
Unregisters an observer for all observer interfaces implemented by the object or its super classes.
|
void register(ECPObserver observer)
observer
- observer objectvoid unregister(ECPObserver observer)
observer
- observer object<T extends ECPObserver> T notify(Class<T> clazz)
T
- type of observerclazz
- class of observerCopyright © 2018. All rights reserved.