MicroBus

General

Category
Free
Tag
Event Buses
License
MIT License
Registered
Jan 16, 2015
Favorites
0
Link
https://github.com/konmik/MicroBus
See also
Coroutines Event Pipe
Livebus
EventListener
Telepathy-IPC
Chamber

Additional

Language
Java
Version
N/A
Created
Oct 16, 2014
Updated
Aug 5, 2015 (Retired)
Owner
Konstantin Mikheev (konmik)
Contributor
Konstantin Mikheev (konmik)
1
Activity
Badge
Generate
Download
Source code

MicroBus - DEPRECATED

The event bus is considered to be an anti-pattern now. Thus, I mark it as deprecated now.

Code that relies heavily on using a bus is an unsupportable mess. Use Observable-Observer patters instead, RxJava preferable.

USAGE

Initialization:

MicroBus bus = new MicroBus();

Definition of a message:

public class Hello {
    public String name;

    public Hello(String name) {
        this.name = name;
    }
}

Receiving class:

class Receiver implements MicroBus.BusEventReceiver {

    public onCreate() {
        bus.register(this, Hello.class);
    }

    public onDestroy() {
        bus.unregister(this, Hello.class);
    }

    @Override
    public void onBusEvent(Object event) {
        if (event instanceof Hello)
            System.out.println("Hello, " + ((Hello)event).name + "!");
    }
}

Sending:

     bus.post(new Hello("Joe"));

Output:

Hello, Joe!

LICENSE

http://www.apache.org/licenses/LICENSE-2.0

(c) 2014 Konstantin Mikheev