Event is a publishing / subscribing event api based off the publish-subscribe pattern.
Event is fully optimized for any implementation, with support for events to be fired on different threads.
EventBus<ExampleEvent> bus = EventBus.of(ExampleEvent.class);
This is a base event you can extend for different actions
public static class ExampleEvent {
}
// Using java 8's lambdas
bus.register(ExampleEvent.class, (EventHandler<ExampleEvent>) event -> {
System.out.println("Hey!");
});
// Using regular java
bus.register(ExampleEvent.class, new EventHandler<ExampleEvent>() {
@Override
public void handle(ExampleEvent event) throws Throwable {
System.out.println("Hey!");
}
});
You can also make a subscriber from a class with methods annotated with @Subscribe
bus.register(new ExampleSubscriber());
public static class ExampleSubscriber {
@Subscribe(order = 1)
private void onExampleEvent(ExampleEvent event) {
System.out.println("Hey!");
}
}