Package org.refcodes.eventbus
Enum DispatchStrategy
- java.lang.Object
-
- java.lang.Enum<DispatchStrategy>
-
- org.refcodes.eventbus.DispatchStrategy
-
public enum DispatchStrategy extends java.lang.Enum<DispatchStrategy>
TheDispatchStrategy
defines how child events are published within a parent event publish cycle.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description ASYNC
Same as theSEQUENTIAL
approach with the difference that the sequential dispatch process is done asynchronously, freeing your parent's thread immediately after publishing your parent event.CASCADE
The parent (invoker) thread is used to publish the parent's event to all matching observers (and is blocked till done).PARALLEL
Each matching observer is invoked in its own thread.SEQUENTIAL
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 useSEQUENTIAL
as well).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DispatchStrategy
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static DispatchStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
SEQUENTIAL
public static final DispatchStrategy SEQUENTIAL
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 useSEQUENTIAL
as well). Any observer (directly or indirectly) invoked by your invoking thread can block your invoking thread.
-
ASYNC
public static final DispatchStrategy ASYNC
Same as theSEQUENTIAL
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.
-
CASCADE
public static final DispatchStrategy CASCADE
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). TheCASCADE
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 theSEQUENTIAL
strategy for publishing their events.
-
PARALLEL
public static final DispatchStrategy PARALLEL
Each matching observer is invoked in its own thread. No observer can block your invoking thread.
-
-
Method Detail
-
values
public static DispatchStrategy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DispatchStrategy c : DispatchStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DispatchStrategy valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
-