Hi @sockeqwe .
Im using a modified version of your EventBus here. Thanks, it is helping me a LOT. When my changes become stable, I will offer it to the project, and if you think that it haves any clue to your component proposal, i will be happy to contribute :).
Basically, my changes are:
- A division little division:
- Handler Manager (manages the envent handler registration and dispatching, but does not permit fire events over it). Its only to listen and respond for events.
- An Application Handler Manager, that can be attached to the application context, allowing users to create application scoped handlers that will will receive application events.
- An Session Handler Manager, that can be attached to any Vaadin Session, so the user can attach session scoped handlers that will have same lifecicle as the Vaadin Session. It will receive application and session scope events.
- EventRouter
- Allows users to fire events over it, bind other EventRouters on it, but not allow handler registrations. This is useful to memory management, avoiding a handler registration on a global object.
- Session Router: A EventRouter that can have one instance per Vaadin Session, and is bound to application router, to receive global events (Like your GlobalEventBus). Events fired here, is delivered to all connected EventBus.
- Application EventRouter (A Event Router proposed to be used as a singleton on a application. Events fired here is routed to all event routers, and in all their binded EventBus'es.
- EventBus - Is a EventRouter and a HandlerManager, to be used in a component scope, like in a Presenter. It can be bound to the SessionRouter, to receive Session and Application Scope events. It can be used to fire events locally, or in session or application.
Well, its only a hierarchical separation with few implementations, but it is helping me, a lot. Now even more with Push Events, that can traverse session and application context.
About my Question.
How you deal with Generic Events? Like:
EntitySavedEvent
eventBus.fireEvent(new EntitySavedEntity(person));
eventBus.fireEvent(new EntitySavedEntity(book));
Firing this two events will deliver the event to any EntitySaveEntity Handler, and if it is not expecting a Person or a Book, it will cause ClassCast Exceptions!
Thanks a lot!