java.lang.Object
org.refcodes.eventbus.EventBusSugar
Declarative syntactic sugar which may be statically imported in order to
allow declarative definitions for the
EventBusEventMatcher
elements.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
protected static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends EventBusEventImpl,
A>
EventBusEventMatcheractionEqualWith
(A aAction) Factory method to create an "EQUAL WITH" matcher for the given action compared with the action stored in theEventMetaData
.static EventBusEventMatcher
aliasEqualWith
(String aAlias) Factory method to create an "EQUAL WITH" matcher for the given name compared with the name stored in theEventMetaData
.static EventBusEventMatcher
and
(EventBusEventMatcher... aEventMatchers) Factory method to create an "AND" matcher for the given matchers.static EventBus
Constructs theEventBus
with theDispatchStrategy.ASYNC
when publishing events: Same as theDispatchStrategy.SEQUENTIAL
approach with the difference that the sequential dispatch process is done asynchronously, freeing your parent's thread immediately after publishing your parent event.static EventBus
asyncDispatchBus
(boolean isDaemon) Constructs theEventBus
with theDispatchStrategy.ASYNC
when publishing events: Same as theDispatchStrategy.SEQUENTIAL
approach with the difference that the sequential dispatch process is done asynchronously, freeing your parent's thread immediately after publishing your parent event.static EventBus
Constructs theEventBus
with theDispatchStrategy.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).static EventBus
cascadeDispatchBus
(boolean isDaemon) Constructs theEventBus
with theDispatchStrategy.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).static EventBusEventMatcher
catchAll()
Catches all events, no matching is done.static EventBusEventMatcher
Catches no event, no matching is done.static EventBusEventMatcher
channelEqualWith
(String aChannel) Factory method to create an "EQUAL WITH" matcher for the given channel compared with the channel stored in theEventMetaData
.static EventBus
eventBus()
static EventBus
eventBus
(boolean isDaemon) static EventBusEventMatcher
groupEqualWith
(String aGroup) Factory method to create an "EQUAL WITH" matcher for the given group compared with the group stored in theEventMetaData
.static EventBusEventMatcher
isAssignableFrom
(Class<?> aEventType) Factory method to create an event matcher by event type.static EventBusEventMatcher
or
(EventBusEventMatcher... aEventMatchers) Factory method to create an "OR" matcher for the given matchers.static EventBus
Constructs theEventBus
with theDispatchStrategy.PARALLEL
when publishing events: Each matching observer is invoked in its own thread.static EventBus
parallelDispatchBus
(boolean isDaemon) Constructs theEventBus
with theDispatchStrategy.PARALLEL
when publishing events: Each matching observer is invoked in its own thread.static <PT> EventBusEventMatcher
publisherIsAssignableFrom
(Class<? extends PT> aPublisherType) Factory method to create an event matcher by event publisher type.static EventBus
Constructs theEventBus
with theDispatchStrategy.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 useDispatchStrategy.SEQUENTIAL
as well).static EventBus
sequentialDispatchBus
(boolean isDaemon) Constructs theEventBus
with theDispatchStrategy.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 useDispatchStrategy.SEQUENTIAL
as well).static EventBusEventMatcher
uidIdEqualWith
(String aUid) Factory method to create an "EQUAL WITH" matcher for the given UID compared with the UID stored in theEventMetaData
.
-
Constructor Details
-
EventBusSugar
public EventBusSugar()
-
-
Method Details
-
eventBus
- Returns:
- The accordingly configured
EventBus
.
-
eventBus
-
parallelDispatchBus
Constructs theEventBus
with theDispatchStrategy.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
Constructs theEventBus
with theDispatchStrategy.PARALLEL
when publishing events: Each matching observer is invoked in its own thread. No observer can block your invoking thread. -
sequentialDispatchBus
Constructs theEventBus
with theDispatchStrategy.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 useDispatchStrategy.SEQUENTIAL
as well). Any observer (directly or indirectly) invoked by your invoking thread can block your invoking thread.- Returns:
- The accordingly configured
EventBus
.
-
sequentialDispatchBus
Constructs theEventBus
with theDispatchStrategy.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 useDispatchStrategy.SEQUENTIAL
as well). Any observer (directly or indirectly) invoked by your invoking thread can block your invoking thread. -
asyncDispatchBus
Constructs theEventBus
with theDispatchStrategy.ASYNC
when publishing events: Same as theDispatchStrategy.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
Constructs theEventBus
with theDispatchStrategy.ASYNC
when publishing events: Same as theDispatchStrategy.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. -
cascadeDispatchBus
Constructs theEventBus
with theDispatchStrategy.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). TheDispatchStrategy.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 theDispatchStrategy.SEQUENTIAL
strategy for publishing their events.- Returns:
- The accordingly configured
EventBus
.
-
cascadeDispatchBus
Constructs theEventBus
with theDispatchStrategy.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). TheDispatchStrategy.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 theDispatchStrategy.SEQUENTIAL
strategy for publishing their events. -
catchAll
Catches all events, no matching is done.- Returns:
- The "catch-all"
EventBusEventMatcher
.
-
catchNone
Catches no event, no matching is done.- Returns:
- The "catch-none"
EventBusEventMatcher
.
-
isAssignableFrom
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
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
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
Factory method to create an "EQUAL WITH" matcher for the given name compared with the name stored in theEventMetaData
.- Parameters:
aAlias
- The name to be compared with aGenericMetaDataEvent
'sEventMetaData
's name property.- Returns:
- An "EQUAL WITH" matcher regarding the
GenericMetaDataEvent
's name property.
-
groupEqualWith
Factory method to create an "EQUAL WITH" matcher for the given group compared with the group stored in theEventMetaData
.- Parameters:
aGroup
- The group to be compared with aGenericMetaDataEvent
'sEventMetaData
's group property.- Returns:
- An "EQUAL WITH" matcher regarding the
GenericMetaDataEvent
's group property.
-
channelEqualWith
Factory method to create an "EQUAL WITH" matcher for the given channel compared with the channel stored in theEventMetaData
.- Parameters:
aChannel
- The channel to be compared with aGenericMetaDataEvent
'sEventMetaData
's channel property.- Returns:
- An "EQUAL WITH" matcher regarding the
GenericMetaDataEvent
's channel property.
-
uidIdEqualWith
Factory method to create an "EQUAL WITH" matcher for the given UID compared with the UID stored in theEventMetaData
.- Parameters:
aUid
- The UID to be compared with aGenericMetaDataEvent
'sEventMetaData
's UID property.- Returns:
- An "EQUAL WITH" matcher regarding the
GenericMetaDataEvent
's UID property.
-
actionEqualWith
Factory method to create an "EQUAL WITH" matcher for the given action compared with the action stored in theEventMetaData
.- Type Parameters:
E
- the element typeA
- 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 aGenericMetaDataEvent
'sEventMetaData
's action property.- Returns:
- An "EQUAL WITH" matcher regarding the
GenericActionEvent
's action property.
-