Class EventHandlerBuilder<State,Event>
- java.lang.Object
-
- akka.persistence.typed.javadsl.EventHandlerBuilder<State,Event>
-
public final class EventHandlerBuilder<State,Event> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description EventHandlerBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EventHandler<State,Event>
build()
static <State,Event>
EventHandlerBuilder<State,Event>builder()
EventHandlerBuilderByState<State,State,Event>
forAnyState()
The handlers defined by this builder are used for any state.EventHandlerBuilderByState<State,State,Event>
forNonNullState()
The handlers defined by this builder are used for any notnull
state.EventHandlerBuilderByState<State,State,Event>
forNullState()
The handlers defined by this builder are used when the state isnull
.<S extends State>
EventHandlerBuilderByState<S,State,Event>forState(java.lang.Class<S> stateClass, java.util.function.Predicate<S> statePredicate)
Use this method to define event handlers that are selected when the passed predicate holds true for a given subtype of your model.EventHandlerBuilderByState<State,State,Event>
forState(java.util.function.Predicate<State> statePredicate)
Use this method to define event handlers that are selected when the passed predicate holds true.<S extends State>
EventHandlerBuilderByState<S,State,Event>forStateType(java.lang.Class<S> stateClass)
Use this method to define command handlers for a given subtype of your model.
-
-
-
Method Detail
-
builder
public static <State,Event> EventHandlerBuilder<State,Event> builder()
-
forState
public EventHandlerBuilderByState<State,State,Event> forState(java.util.function.Predicate<State> statePredicate)
Use this method to define event handlers that are selected when the passed predicate holds true.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
- Parameters:
statePredicate
- The handlers defined by this builder are used when thestatePredicate
istrue
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
forState
public <S extends State> EventHandlerBuilderByState<S,State,Event> forState(java.lang.Class<S> stateClass, java.util.function.Predicate<S> statePredicate)
Use this method to define event handlers that are selected when the passed predicate holds true for a given subtype of your model. Useful when the model is defined as class hierarchy.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
- Parameters:
stateClass
- The handlers defined by this builder are used when the state is an instance of thestateClass
statePredicate
- The handlers defined by this builder are used when thestatePredicate
istrue
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
forStateType
public <S extends State> EventHandlerBuilderByState<S,State,Event> forStateType(java.lang.Class<S> stateClass)
Use this method to define command handlers for a given subtype of your model. Useful when the model is defined as class hierarchy.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
- Parameters:
stateClass
- The handlers defined by this builder are used when the state is an instance of thestateClass
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
forNullState
public EventHandlerBuilderByState<State,State,Event> forNullState()
The handlers defined by this builder are used when the state isnull
. This variant is particular useful when the empty state of your model is defined asnull
.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
forNonNullState
public EventHandlerBuilderByState<State,State,Event> forNonNullState()
The handlers defined by this builder are used for any notnull
state.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
forAnyState
public EventHandlerBuilderByState<State,State,Event> forAnyState()
The handlers defined by this builder are used for any state. This variant is particular useful for models that have a single type (ie: no class hierarchy).Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers. Extra care should be taken when using
forAnyState()
as it will match any state. Any event handler define after it will never be reached.- Returns:
- A new, mutable, EventHandlerBuilderByState
-
build
public EventHandler<State,Event> build()
-
-