Pustike EventBus

Pustike EventBus is a fork of Guava EventBus, which is probably the most commonly known event bus for Java. Most of the documentation here and test cases are from Guava itself.

EventBus is a library providing publisher/subscriber pattern for loose coupling between components(event senders and receivers), by sending messages to each other indirectly. Some objects register with the bus to be notified when certain events of interest occur. And some publish events on the bus. The bus notifies each of the registrants when the event is published. So registrant objects and event-source objects need not know about each other directly. Each may join or depart the bus at any time. Thus it enables central communication between components, simplifies the code and removes direct dependencies.

Pustike EventBus

The Guava Project contains several core libraries and is distributed as a single module that has a size of ~2.2MB (as of v19.0). An application using only the EventBus will also need to include the full Guava dependency. So, this is an effort to extract only the event bus library from Guava project without any other dependencies.

This library also provides few additional features / changes, like:

  • Typed Events supporting event type specific subscribers
  • Error handling using ExceptionEvents
  • WeakReference to target subscribers
  • @Subscribe(threadSafe = true) instead of @AllowConcurrentEvents
  • Unregistering a not-registered subscriber doesn’t throw exception
  • Allows using an external cache for loading subscriber methods and event type hierarchy
  • Only ~20kB in size when using default subscriber cache
  • Java 11 as the min requirement (Guava supports Java 6 onwards)

Documentation:

  • User’s Guide is included in the project’s README.md file.
  • Latest API docs are accessible here.

Download:

The most recent release is v1.5.0 (2018-09-28), and it is available from Maven central repository.

To add it as a dependency in Maven builds, use the following:

<dependency>
    <groupId>io.github.pustike</groupId>
    <artifactId>pustike-eventbus</artifactId>
    <version>1.5.0</version>
</dependency>

Or, download the latest JAR(~20kB) from Maven Central.

License: This library is published under the Apache License, Version 2.0