Skip to content

A simple Event Aggregator written in Kotlin for the JVM

Notifications You must be signed in to change notification settings

Hc747/KEventAggregator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KEventAggregator

A simple Event Aggregator written in Kotlin.

An event aggregator is used to pass messages (events) to interested parties in a loosely coupled manner and is closely related to the Observer pattern.

More information on the Event Aggregator pattern is provided by Martin Fowler in his blog here.

Limitations

  • Event Deregistration: this implementation at present date only supports the (dynamic) registration of event handlers. In the future, a mechanism for dynamically deregistering events should be implemented.
  • Coroutines / Green threads: this implementation at present date only supports the JVM's native thread implementation.

Usage

  • Create Event Handlers

Java

class MyEventHandler {
    @EventHandler
    public /*static*/ void myEventHandlingMethod(MyEvent event) {
        ...
    }
}
  • Create an Event Aggregator instance
EventAggregator aggregator = new EventAggregator();
  • Register Event Handlers with the Event Aggregator
aggregator.register(MyEventHandler.class); //register static methods
...
aggregator.register(new MyEventHandler()); //register instance methods
...
aggregator.onEvent(MyEvent.class, event -> {...}); //register a standalone event handler 
  • Dispatch events to interested parties (event handlers)
aggregator.dispatch(event, executor_service, dispatch_mode);
...
aggregator.dispatchAll(events, executor_service, dispatch_mode);

Kotlin

class MyEventHandler {
    @EventHandler
    /*@JvmStatic*/
    fun myEventHandlingFun(event: MyEvent) {
        ...
    }
}
  • Create an Event Aggregator instance
val aggregator = EventAggregator()
  • Register Event Handlers with the Event Aggregator
aggregator.register(MyEventHandler::class/*.java*/) //register static methods
...
aggregator.register(MyEventHandler()) //register instance methods
...
aggregator.onEvent(MyEvent::class/*.java*/) { event -> ... } //register a standalone event handler 
  • Dispatch events to interested parties (event handlers)
aggregator.dispatch(event, executor_service, dispatch_mode)
...
aggregator.dispatchAll(events, executor_service, dispatch_mode)

A reference implementation is provided in the 'example' package.

About

A simple Event Aggregator written in Kotlin for the JVM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages