Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niqumu/eventbus
Tiny Java event bus
https://github.com/niqumu/eventbus
event-bus event-driven events guava guava-event-bus java
Last synced: 28 days ago
JSON representation
Tiny Java event bus
- Host: GitHub
- URL: https://github.com/niqumu/eventbus
- Owner: niqumu
- Created: 2024-04-23T13:31:28.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-23T15:01:44.000Z (8 months ago)
- Last Synced: 2024-04-24T17:22:17.258Z (8 months ago)
- Topics: event-bus, event-driven, events, guava, guava-event-bus, java
- Language: Java
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## EventBus
This project is an extremely tiny and fast Java EventBus, originally written for Minecraft modding, but applicable to any Java application.
This EventBus operates on the simple concept of *Event Subscribers* and *Event Handlers*. Event Subscribers are classes that subscribe an instance of themselves to receive posted events, and Event Handlers are methods within Event Subscribers
annotated via ``@EventHandler`` that handle matching posted events. The EventBus API provides a base ``Event`` interface that custom events should implement for usage with the bus. Developers can write their own custom implementations of the
``EventBus`` interface.## Examples
Example of a custom event:
```java
import dev.niqumu.eventbus.api.Event;public class DummyEvent implements Event {
public final String dummyName;
public final int dummyId;public DummyEvent(String name, int id) {
this.dummyName = name;
this.dummyId = id;
}
}
```Example of an event listen for the custom event:
```java
public class DummyEventListener {
public DummyEventListener() {
eventBus.registerSubscriber(this);
}@EventHandler
public void onDummyEvent(DummyEvent event) {
// ...
}
}
```Example of posting a custom event:
```java
DummyEvent event = new DummyEvent(name, id);
eventBus.postEvent(event);
```