Lightweight implementation of a publish/subscribe library inspired by Otto
The latest released version of the Minibus library artefact is available as:
<dependency>
<groupId>fr.inria.minibus</groupId>
<artifactId>minibus-library</artifactId>
<version>1.0</version>
</dependency>
The currently developed version of the MiniBus library artefact is available as:
<dependency>
<groupId>fr.inria.minibus</groupId>
<artifactId>minibus-library</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
MiniBus is a Maven managed project. All you have to do is to invoke the install
command from the root directory (MINIBUS_DIR
):
cd $MINIBUS_DIR
mvn install
MiniBus supports the usage of POJO events as long as the filtered fields are exposed:
public class Event {
public final int value;
public Event(int v) {
this.value = v;
}
}
Enlistment of event handlers is achieved through the interface Subscriber and the annotation Subscribe:
public class SubscribingObject {
public SubscribingObject(Subscriber bus) {
bus.subscribe(this);
}
@Subscribe
public String onAnyValue(Event e) {
return "Received event with value " + e.value;
}
@Subscribe("value>0")
public String onStrictPositiveValue(Event e) {
return "Event "+e+" is strictly positive ";
}
@Subscribe
public void print(String msg) {
System.out.println(msg);
}
}
Delivery of events is ensured by the interface Publisher, which can be used to asynchronously post events:
public class PublishingObject {
public PublishingObject(Publisher bus) {
bus.publish(new Event(10))
bus.publish(new Event(-10))
}
}
public class Application {
public static void main (String[] args) {
Bus bus = new EventBus(10);
new SubscribingObject(bus);
new PublishingObject(bus);
}
}
Copyright (C) 2014 University Lille 1, Inria
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.