Class EventBusSugar

java.lang.Object
org.refcodes.eventbus.EventBusSugar

public class EventBusSugar extends Object
Declarative syntactic sugar which may be statically imported in order to allow declarative definitions for the EventBusEventMatcher elements.
  • Method Details

    • eventBus

      public static EventBus eventBus()
      Constructs the EventBus with the DispatchStrategy as of EventBus().
      Returns:
      The accordingly configured EventBus.
    • eventBus

      public static EventBus eventBus(boolean isDaemon)
      Constructs the EventBus with the DispatchStrategy as of EventBus(boolean).
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      Returns:
      The accordingly configured EventBus.
    • parallelDispatchBus

      public static EventBus parallelDispatchBus()
      Constructs the EventBus with the DispatchStrategy.PARALLEL when publishing events: Each matching observer is invoked in its own thread. No observer can block your invoking thread.
      Returns:
      The accordingly configured EventBus.
    • parallelDispatchBus

      public static EventBus parallelDispatchBus(boolean isDaemon)
      Constructs the EventBus with the DispatchStrategy.PARALLEL when publishing events: Each matching observer is invoked in its own thread. No observer can block your invoking thread.
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      Returns:
      The accordingly configured EventBus.
    • sequentialDispatchBus

      public static EventBus sequentialDispatchBus()
      Constructs the EventBus with the DispatchStrategy.SEQUENTIAL when publishing events: The parent (invoker) thread is used to publish the parent's event as well as the child events published by the matching observers of the parent event (and so on, in case them use DispatchStrategy.SEQUENTIAL as well). Any observer (directly or indirectly) invoked by your invoking thread can block your invoking thread.
      Returns:
      The accordingly configured EventBus.
    • sequentialDispatchBus

      public static EventBus sequentialDispatchBus(boolean isDaemon)
      Constructs the EventBus with the DispatchStrategy.SEQUENTIAL when publishing events: The parent (invoker) thread is used to publish the parent's event as well as the child events published by the matching observers of the parent event (and so on, in case them use DispatchStrategy.SEQUENTIAL as well). Any observer (directly or indirectly) invoked by your invoking thread can block your invoking thread.
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      Returns:
      The accordingly configured EventBus.
    • asyncDispatchBus

      public static EventBus asyncDispatchBus()
      Constructs the EventBus with the DispatchStrategy.ASYNC when publishing events: Same as the DispatchStrategy.SEQUENTIAL approach with the difference that the sequential dispatch process is done asynchronously, freeing your parent's thread immediately after publishing your parent event. Exactly one extra thread is created to kick off the asynchronous way of doing a sequential dispatch. Any observer (directly or indirectly) invoked by the "asynchronous" thread can block any other observer in that chain, but not your invoking thread.
      Returns:
      The accordingly configured EventBus.
    • asyncDispatchBus

      public static EventBus asyncDispatchBus(boolean isDaemon)
      Constructs the EventBus with the DispatchStrategy.ASYNC when publishing events: Same as the DispatchStrategy.SEQUENTIAL approach with the difference that the sequential dispatch process is done asynchronously, freeing your parent's thread immediately after publishing your parent event. Exactly one extra thread is created to kick off the asynchronous way of doing a sequential dispatch. Any observer (directly or indirectly) invoked by the "asynchronous" thread can block any other observer in that chain, but not your invoking thread.
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      Returns:
      The accordingly configured EventBus.
    • cascadeDispatchBus

      public static EventBus cascadeDispatchBus()
      Constructs the EventBus with the DispatchStrategy.CASCADE when publishing events: The parent (invoker) thread is used to publish the parent's event to all matching observers (and is blocked till done). Child events published by the matching observers invoked with the parent's event are queued until the parent's thread finished dispatching the parent's event. The queued child events then are published in their own separate threads, now considered being parent events with their according parent threads, to all matching observers (dispatching as described above). The DispatchStrategy.CASCADE strategy is useful when publishing lifecycle or bootstrapping events to make sure, that any observer was notified before publishing post-lifecycle actions. Observers directly invoked by your invoking thread can block your invoking thread and indirectly invoked observers called by your directly invoked observers using the DispatchStrategy.SEQUENTIAL strategy for publishing their events.
      Returns:
      The accordingly configured EventBus.
    • cascadeDispatchBus

      public static EventBus cascadeDispatchBus(boolean isDaemon)
      Constructs the EventBus with the DispatchStrategy.CASCADE when publishing events: The parent (invoker) thread is used to publish the parent's event to all matching observers (and is blocked till done). Child events published by the matching observers invoked with the parent's event are queued until the parent's thread finished dispatching the parent's event. The queued child events then are published in their own separate threads, now considered being parent events with their according parent threads, to all matching observers (dispatching as described above). The DispatchStrategy.CASCADE strategy is useful when publishing lifecycle or bootstrapping events to make sure, that any observer was notified before publishing post-lifecycle actions. Observers directly invoked by your invoking thread can block your invoking thread and indirectly invoked observers called by your directly invoked observers using the DispatchStrategy.SEQUENTIAL strategy for publishing their events.
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      Returns:
      The accordingly configured EventBus.
    • catchAll

      public static EventBusEventMatcher catchAll()
      Catches all events, no matching is done.
      Returns:
      The "catch-all" EventBusEventMatcher.
    • catchNone

      public static EventBusEventMatcher catchNone()
      Catches no event, no matching is done.
      Returns:
      The "catch-none" EventBusEventMatcher.
    • isAssignableFrom

      public static EventBusEventMatcher isAssignableFrom(Class<?> aEventType)
      Factory method to create an event matcher by event type.
      Parameters:
      aEventType - The event type to be matched by this matcher.
      Returns:
      An event matcher by event type.
    • publisherIsAssignableFrom

      public static <PT> EventBusEventMatcher publisherIsAssignableFrom(Class<? extends PT> aPublisherType)
      Factory method to create an event matcher by event publisher type.
      Type Parameters:
      PT - The publisher descriptor type
      Parameters:
      aPublisherType - The event publisher type to be matched by this matcher.
      Returns:
      An event matcher by event type.
    • or

      @SafeVarargs public static EventBusEventMatcher or(EventBusEventMatcher... aEventMatchers)
      Factory method to create an "OR" matcher for the given matchers.
      Parameters:
      aEventMatchers - The matchers to be combined by an "OR".
      Returns:
      An "OR" matcher.
    • and

      @SafeVarargs public static EventBusEventMatcher and(EventBusEventMatcher... aEventMatchers)
      Factory method to create an "AND" matcher for the given matchers.
      Parameters:
      aEventMatchers - The matchers to be combined by an "AND".
      Returns:
      An "AND" matcher.
    • aliasEqualWith

      public static EventBusEventMatcher aliasEqualWith(String aAlias)
      Factory method to create an "EQUAL WITH" matcher for the given name compared with the name stored in the EventMetaData.
      Parameters:
      aAlias - The name to be compared with a MetaDataEvent's EventMetaData's name property.
      Returns:
      An "EQUAL WITH" matcher regarding the MetaDataEvent's name property.
    • groupEqualWith

      public static EventBusEventMatcher groupEqualWith(String aGroup)
      Factory method to create an "EQUAL WITH" matcher for the given group compared with the group stored in the EventMetaData.
      Parameters:
      aGroup - The group to be compared with a MetaDataEvent's EventMetaData's group property.
      Returns:
      An "EQUAL WITH" matcher regarding the MetaDataEvent's group property.
    • channelEqualWith

      public static EventBusEventMatcher channelEqualWith(String aChannel)
      Factory method to create an "EQUAL WITH" matcher for the given channel compared with the channel stored in the EventMetaData.
      Parameters:
      aChannel - The channel to be compared with a MetaDataEvent's EventMetaData's channel property.
      Returns:
      An "EQUAL WITH" matcher regarding the MetaDataEvent's channel property.
    • uidIdEqualWith

      public static EventBusEventMatcher uidIdEqualWith(String aUid)
      Factory method to create an "EQUAL WITH" matcher for the given UID compared with the UID stored in the EventMetaData.
      Parameters:
      aUid - The UID to be compared with a MetaDataEvent's EventMetaData's UID property.
      Returns:
      An "EQUAL WITH" matcher regarding the MetaDataEvent's UID property.
    • actionEqualWith

      public static <E extends EventBusEvent, A> EventBusEventMatcher actionEqualWith(A aAction)
      Factory method to create an "EQUAL WITH" matcher for the given action compared with the action stored in the EventMetaData.
      Type Parameters:
      E - the element type
      A - The type of the action stored in the event. CAUTION: The drawback of not using generic generic type declaration on a class level is no granted type safety, the advantage is the ease of use: Sub-classes can be used out of the box.
      Parameters:
      aAction - The action to be compared with a MetaDataEvent's EventMetaData's action property.
      Returns:
      An "EQUAL WITH" matcher regarding the ActionEvent's action property.