A high-performance, annotation-based EventBus for Java applications with MethodHandles for optimal efficiency.
- High-performance event dispatching using MethodHandles instead of slow reflection
- Multiple event handlers in a single class via @Handler annotation
- Priority-based event handler execution
- Support for both annotation-based and functional (Consumer) event handling
- Type-safe event dispatching
- Simple and intuitive API
repositories {
mavenCentral()
}
dependencies {
implementation("dev.hogoshi.tensai:tensai:X.X.X")
}<dependencies>
<dependency>
<groupId>dev.hogoshi.tensai</groupId>
<artifactId>tensai</artifactId>
<version>X.X.X</version>
</dependency>
</dependencies>Note: Replace
X.X.Xwith the desired version tag from the releases page.
public class TestEvent {
private final String message;
public TestEvent(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}public class MyEventListener {
@Handler(priority = 5)
private void onTestEvent(TestEvent event) {
System.out.println("TestEvent received: " + event.getMessage());
}
@Handler(priority = 10)
public void onAnotherEvent(AnotherEvent event) {
System.out.println("AnotherEvent received: " + event.getName());
}
}// Create event dispatcher
EventDispatcher dispatcher = new EventDispatcher();
// Register event handlers
dispatcher.registerHandler(TestEvent.class, e -> System.out.println("Lambda handler: " + e), 10);
dispatcher.registerHandler(new MyEventListener());
// Dispatch events
dispatcher.dispatch(new TestEvent("Hello World"));
dispatcher.dispatch(new AnotherEvent("Another event"));This project is licensed under the MIT License - see the LICENSE file for details.