This PR is meant to add the possibility to add subscribers at runtime. In this PR, there are some major changes in the code though:
Old Behavior:
Subscribers can only be added at compile time by using the standard @Subscribe annotation on Java methods.
New Behavior:
It is now possible to add subscribers at runtime using the register(Subscriber<T>) method on the bus.
There is no direct AbstractSubscriber anymore. Instead, the code only contains a Subscriber<T> class with the generic parameter T which is the actual event type. The subscriber references an EventHandler<T>, which is a functional interface, meaning that there is only one method that needs to be implemented. An event handler (subscriber) on a bus bus can now be added at runtime with the following:
final List<SubscriberContract> contracts = List.of(new SubscriberContract(
Event.class, // when
List.of(EventB.class, EventC.class), // then
EventCardinality.MANY) // Cardinality
);
bus.register(Subscriber.ofEvent(Event.class)
.handler(event -> { /* do something */ })
.associatedContract(contracts)
.name("identifier for this particular subscriber"));
Of course, the standard way of adding subscribers and specifying annotations is still there. The bus will encapsulate the Java method with this Subscriber and create an EventHandler that simply calls the method.
This PR also contains some minor fixes, such as the empty Result<T> type with correct type.
This PR is meant to add the possibility to add subscribers at runtime. In this PR, there are some major changes in the code though:
@Subscribe
annotation on Java methods.register(Subscriber<T>)
method on the bus.There is no direct
AbstractSubscriber
anymore. Instead, the code only contains aSubscriber<T>
class with the generic parameterT
which is the actual event type. The subscriber references anEventHandler<T>
, which is a functional interface, meaning that there is only one method that needs to be implemented. An event handler (subscriber) on a busbus
can now be added at runtime with the following:Of course, the standard way of adding subscribers and specifying annotations is still there. The bus will encapsulate the Java method with this
Subscriber
and create anEventHandler
that simply calls the method.This PR also contains some minor fixes, such as the empty
Result<T>
type with correct type.