Skip to content

Citymonstret/EventBus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EventBus

A simple and effective subscription based event bus written in Java

What can it do?

EventBus supports synchronous and asynchronous event dispatching. Events may be cancellable. Events are dispatched to annotated subscriber methods.

How does it work?

EventBus used lambda meta factories to access subscriber methods without reflection, using the lambda-factory library. Any object can be dispatched as an event, and a method accepting a single parameter will be able to act on the event.

How to use it?

Create an event bus:

final EventBus bus = new SimpleEventBus();

Create a listener:

public static final class TestListenerClass {
    @Listener public void onString(final String string) {
        new RuntimeException("Found a string: " + string).printStackTrace();
        indicateSuccess = true;
    }
}

Register the listener:

bus.registerListeners(new TestListenerClass());

Dispatch an event:

final String event = "Hello World!";
bus.throwSync(event);

and that is it. Events can also be dispatched asynchronously, by using throwAsync.

JavaDoc can be found in the docs directory.

Maven

EventBus is using the JitPack maven repository.

JitPack Badge

To use it, add the following repository:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

and the following dependency:

<dependency>
    <groupId>com.github.Sauilitired</groupId>
    <artifactId>EventBus</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Contributions & Contact

Contributions are very welcome! The project uses the Google Java code style. The project is licensed under the MIT license.

If you have any further questions or feedback, then feel free to join our Discord.
If the project helped you, then you are free to give me some coffee money via PayPal