|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ECPObserverBus
Bus for application wide notifications on events of various types. Check the type hierarchy of ECPObserver
to
discover possible types.
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 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
Method Summary | ||
---|---|---|
|
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. |
Method Detail |
---|
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 observer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |