GithubHelp home page GithubHelp logo

event-bus's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.