/** * interface describing a generic event, and it's associated meta data, it's this what's going to * get sent in the bus to be dispatched to intrested Subscribers * * @author chermehdi */ publicinterfaceEvent<T> { /** * @returns the stored data associated with the event */ T getData(); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import java.util.Set; /** * Description of a generic subscriber * * @author chermehdi */ publicinterfaceSubscribable { /** * Consume the events dispatched by the bus, events passed as parameter are can only be of type * declared by the supports() Set */ voidhandle(Event<?> event); /** * describes the set of classes the subscribable object intends to handle */ Set<Class<?>> supports(); }
import java.util.List; /** * Description of the contract of a generic EventBus implementation, the library contains two main * version, Sync and Async event bus implementations, if you want to provide your own implementation * and stay compliant with the components of the library just implement this contract * * @author chermehdi */ publicinterfaceEventBus { /** * registers a new subscribable to this EventBus instance */ voidregister(Subscribable subscribable); /** * send the given event in this EventBus implementation to be consumed by interested subscribers */ voiddispatch(Event<?> event); /** * get the list of all the subscribers associated with this EventBus instance */ List<Subscribable> getSubscribers(); }