https://github.com/kevinpriv/keventbus
Performance and thread-safe oriented eventbus
https://github.com/kevinpriv/keventbus
Last synced: about 1 month ago
JSON representation
Performance and thread-safe oriented eventbus
- Host: GitHub
- URL: https://github.com/kevinpriv/keventbus
- Owner: KevinPriv
- License: mit
- Created: 2020-10-10T18:41:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-09T22:31:20.000Z (over 3 years ago)
- Last Synced: 2025-04-07T04:28:33.922Z (2 months ago)
- Language: Kotlin
- Homepage:
- Size: 77.1 KB
- Stars: 10
- Watchers: 1
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KEventBus
JVM Eventbus focused on thread-safety and performance.## Registering
**Kotlin**
```kotlin
// Create eventbus
private val eventBus = eventbus {
invoker { LMFInvoker() }
exceptionHandler { exception -> println("Error occurred in method: ${exception.message}") }
}// Method you would like to subscribe to an event
// Param #1 is MessagedReceivedEvent therefore this method will be subscribed to that class
@Subscribe
fun `subscribed method`(event: MessageReceivedEvent) {
// do something
println(event.message)
}
...
// Register all the @Subscribe 'd methods inside of an instance
eventBus.register(this)```
**Java**
```java
// Create eventbus
private EventBus eventBus = new EventBus(new LMFInvoker(), e -> {
System.out.println("Error occurred in method: " + e.getMessage());
});// Method you would like to subscribe to an event
// Param #1 is MessagedReceivedEvent therefore this method will be subscribed to that class
@Subscribe
public void subscribedMethod(MessageReceivedEvent event) {
System.out.println(event.getMessage());
}
...
// Register all the @Subscribe 'd methods inside of an instance
eventBus.register(this)
```
## Posting
**Kotlin**
```kotlin
// Post all methods subscribed to the event `MessageReceivedEvent`
eventBus.post(MessageReceivedEvent("Hello world"))
```
**Java**
```java
// Post all methods subscribed to the event `MessageReceivedEvent`
eventBus.post(new MessageReceivedEvent("Hello world"));
```
## Unregistering
**Kotlin**
```kotlin
// Remove all @Subscribe 'd methods from an instance
eventBus.unregister(this)
```
**Java**
```java
// Remove all @Subscribe 'd methods from an instance
eventBus.unregister(this)
```