Tiny, lightweight eventing engine.
EventRouter is designed to be a lightweight "Event-Bus-Like" construct that provides a simple and user-friendly api to simplify event-driven architectures. It was designed to work with small to medium size projects, altough it might work well with larger projects too .
Simple. It is really really easy to use:
final EventRouter eventRouter = new EventRouter();
eventRouter.on(MyEventType.class, event -> doSomething());
eventRouter.trigger(new MyEventType());done.
The above code sample adds a Callback<MyEventType> to the eventRouter and triggers it afterwards. Since you can add
Callbacks and trigger Events from anywhere in your codebase it makes it pretty easy to couple several components or
even modules with this mechanism.
You simply instantiate a EventRouter and keep this instance for as long as the bus should be alive. The method
EventRouter#on returns you a Registration which lets you unregister the Callback easily using the
Registration#unregister method.
If you have a closer look at the EventRouter#on method, you'll see that the first parameter is the type, or to be more
specific, the class of the event you want to observe. The second parameter is the Callback which get's triggered when
an event of the specified type gets triggerd - typically a lambda expression which represents the passed Event instance.
If you are looking for some code samples have a look on the EventRouterTest Unit-Test.
- Maven - Dependency Management
I use SemVer for versioning. For the versions available, see the tags on this repository.
- Manfred Huber - Initial work - downdrown