All Known Implementing Classes:
BusImplementation

public interface Bus
A general Bus interface that can handle events of any type, and allows adding subscribers to events. The actual subscriber is always of type Subscriber. If, however, an Object of any other type is passed instead, the respective methods of that class will be looked up and searched for subscribers. Thus, one can either add method-based subscribers from the annotation, or define a subscriber at runtime directly. Each bus has an identifier for logging purposes. It can either be generated or provided by the user.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    acceptEvents(boolean accept)
    Sets whether events can be posted to this bus or not.
    void
    Closes the registration of subscribers.
    The unique identifer of this bus.
    static Bus
    Returns a new instance of this bus with a default identifier.
    static Bus
    Returns a new instance of this bus with the identifier given by name.
    void
    post(Object event)
    Posts an event and calls each handler that are subscribed to, if the interceptors allow that.
    void
    register(Object object)
    Registers an object that contains method annotated by Subscribe annotations.
    <T> void
    register(Subscriber<T> subscriber)
    Registers a subscriber for the event of type T.
    void
    Unregisters either an object containing subscriber methods, or a certain subscriber through the name.
  • Method Details

    • getIdentifier

      String getIdentifier()
      The unique identifer of this bus. This can be generated or provided by the user.
      Returns:
      The unique identifier.
    • register

      <T> void register(Subscriber<T> subscriber)
      Registers a subscriber for the event of type T. The subscriber holds a name that is used to identify it and later be unsubscribed again using unregister(Object).
      Type Parameters:
      T - The event type
      Parameters:
      subscriber - The subscriber holding the event handler.
    • register

      void register(Object object)
      Registers an object that contains method annotated by Subscribe annotations. This object must also be annotated with OnEvents to be correctly registered. The id of these subscribers will be the full canonical name of the method (including the name of the class).
      Parameters:
      object - The object containing subscriber methods.
    • unregister

      void unregister(Object object)
      Unregisters either an object containing subscriber methods, or a certain subscriber through the name. That is, the object parameter can be an arbitrary object of subscriber methods, or of type String that identifies a certain subscriber. Afterwards, those affected subscribers will be ignored upon the respective events.
      Parameters:
      object - The object holding the subscriber methods OR the id of the subscriber as a String.
    • post

      void post(Object event)
      Posts an event and calls each handler that are subscribed to, if the interceptors allow that.
      Parameters:
      event - The event to post.
    • closeRegistration

      void closeRegistration()
      Closes the registration of subscribers. After this method is called, it is not possible to register new objects.
    • acceptEvents

      void acceptEvents(boolean accept)
      Sets whether events can be posted to this bus or not.
      Parameters:
      accept - A flag saying whether events can be posted here. If true, then events can be posted (default behavior). If false, events are not allowed to be posted here until it is opened again.
    • instance

      static Bus instance()
      Returns a new instance of this bus with a default identifier.
      Returns:
      A new instance with default identifier.
    • instance

      static Bus instance(String name)
      Returns a new instance of this bus with the identifier given by name.
      Parameters:
      name - The identifier of the bus that should be created.
      Returns:
      A new bus with the given identifier.