Skip to content

chermehdi/event-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Event Bus

Why?

  • I write a blog post from time to time and this repository is POC to the ideas explained in the blog post.
  • To demonstrate to my students that it's not hard at all to implement such types of ideas.

Running the project

  • It's a maven based project, hence you can just compile and run using maven itself (Just don't forget to install the dependencies and you'll be good to go).
  • Make sure you have at least a JDK 1.8 or higher installed in your machine and an IDE would be nice to have.
  • Take a look at the unit tests to see how to use both implementations if the EventBus. Also play with code a little, you can read the blog post for additional explanations.

Usage example

Using Common EventBus implementation
EventBus eventBus = EventBusFactory.createSingletonSyncEventBus();
Subscribable subs = new EventSubscribable(); // your own implementation of the Subscribable interface
eventBus.register(subs);

// later on on the code ... 
eventBus.dispatch(new EventStub());
Using The idea of Guava's EventBus
EventBus eventBus = new EventBus("myEventBusName")
Handler handler = new Handler();

eventBus.register(handler);

class Event {
  // your event's state/behaviours
}
class Handler {

  @Subscribe("myEventBusName")
  @Subscribe("multiEventSubscribingIsAlsoSupported")
  public void handleEvent(Event event) {
    // consume the event here
  }
}

// later on in the code
eventBus.post(new Event());

// can also unregister handlers later on
eventBus.register(handler);

Contribution

  • Bug fixes, improvements, and more features are all welcomed 😁 (Just make sure to fully describe what you've done and write some unit tests if necessary)

About

An Event Bus simple implementation inspired by google and my own design (for blogging purposes)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages