Skip to content

zhogoshi/tensai

Repository files navigation

Tensai

A high-performance, annotation-based EventBus for Java applications with MethodHandles for optimal efficiency.

Features

  • 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

Installation

Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation("dev.hogoshi.tensai:tensai:X.X.X")
}

Maven

<dependencies>
    <dependency>
        <groupId>dev.hogoshi.tensai</groupId>
        <artifactId>tensai</artifactId>
        <version>X.X.X</version>
    </dependency>
</dependencies>

Note: Replace X.X.X with the desired version tag from the releases page.

Usage

Creating Event Classes

public class TestEvent {
    private final String message;
    
    public TestEvent(String message) {
        this.message = message;
    }
    
    public String getMessage() {
        return message;
    }
}

Creating Event Listeners

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());
    }
}

Dispatching Events

// 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"));

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Simple, Lightweight, Useful and pretty fast Event Bus written in 3 classes

Resources

License

Stars

Watchers

Forks

Contributors

Languages