Easybus Core

Simple, No Frills Event Bus for Java - Core and Sample Implementation

License

License

GroupId

GroupId

me.kisoft
ArtifactId

ArtifactId

easybus-core
Last Version

Last Version

2.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

Easybus Core
Simple, No Frills Event Bus for Java - Core and Sample Implementation

Download easybus-core

How to add to project

<!-- https://jarcasting.com/artifacts/me.kisoft/easybus-core/ -->
<dependency>
    <groupId>me.kisoft</groupId>
    <artifactId>easybus-core</artifactId>
    <version>2.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/me.kisoft/easybus-core/
implementation 'me.kisoft:easybus-core:2.1.2'
// https://jarcasting.com/artifacts/me.kisoft/easybus-core/
implementation ("me.kisoft:easybus-core:2.1.2")
'me.kisoft:easybus-core:jar:2.1.2'
<dependency org="me.kisoft" name="easybus-core" rev="2.1.2">
  <artifact name="easybus-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.kisoft', module='easybus-core', version='2.1.2')
)
libraryDependencies += "me.kisoft" % "easybus-core" % "2.1.2"
[me.kisoft/easybus-core "2.1.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.reflections : reflections jar 0.9.11
org.apache.commons : commons-lang3 jar 3.10

provided (2)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.12
com.google.auto.service : auto-service jar 1.0-rc2

test (1)

Group / Artifact Type Version
junit : junit jar 4.13

Project Modules

There are no modules declared in this project.

Maven Central

EasyBus

Easy bus is a simple, event bus for java designed for simplicity and java practices in mind

  • Annotation-Based
  • Sync and Async
  • Auto-Registration of Events
  • Compile-Time checking for events & handlers

Useage

Installation

To use the easybus, add the following into your pom.xml

<dependency>
  <groupId>me.kisoft</groupId>
  <artifactId>easybus-core</artifactId>
  <version>${LATEST_VERSION}</version>
</dependency>

If you want to use a specific backing implementation of easybus, you can also import that specific implementation which will also import easybus

Defining Events and Handlers

Afterwards, you will need to define your events and handlers using the @Handle and @Event annotations

Defining Events

@Event
public class MyEvent{
  // your code here
}

Defining Handlers

@Handle(event=MyEvent.class)
public class MyEventHandler{
   public void handle(MyEvent event){
     // your code here
   }
}

Note that the handle(MyEvent event) method is mandatory, and it is the method that will be called by the event bus. The Method MUST be called handle and have the same type as your target event.

Adding Events and Handlers

You must also create a new event bus and specify the packages or classloaders your events are in

EasyBus bus = new EasyBus();
bus.search("my.package.name")
.search("my.second.package");

You will probably need to wrap the event bus as a singleton or maintain some reference to it, but that is just you coding.

Posting Events

bus.post(new MyEvent());

Async Handlers

Async Handlers are defined in the same way as handlers, except that they run in a seperate thread from the current thread. This is more of a hint to the backing bus; its not mandatory to honor async execution.

@Handle(event=MyEvent.class,async=true)
public class MyEventAsyncHandler{
   public void handle(MyEvent event){
     // your code here
   }
}

Implementing a Backing Bus

To implement a backing bus, all you need to do is implement the me.kisoft.easybus.Bus Interface, and when creating a new EasyBus, you need to use the new EasyBus(Bus bus) constructor to change the backing bus, or create your own factory

Versions

Version
2.1.2
2.1.1
2.1.0
2.0.0