Class EventHandlerBuilderByState<S extends State,State,Event>
- java.lang.Object
-
- akka.persistence.typed.javadsl.EventHandlerBuilderByState<S,State,Event>
-
public final class EventHandlerBuilderByState<S extends State,State,Event> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description EventHandlerBuilderByState(java.lang.Class<S> stateClass, java.util.function.Predicate<S> statePredicate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EventHandler<State,Event>
build()
Builds and returns a handler from the appended states.static <S extends State,State,Event>
EventHandlerBuilderByState<S,State,Event>builder(java.lang.Class<S> stateClass)
static <State,Event>
EventHandlerBuilderByState<State,State,Event>builder(java.util.function.Predicate<State> statePredicate)
EventHandler<State,Event>
onAnyEvent(java.util.function.BiFunction<State,Event,State> handler)
Match any event.EventHandler<State,Event>
onAnyEvent(java.util.function.Function<Event,State> handler)
Match any event.<E extends Event>
EventHandlerBuilderByState<S,State,Event>onEvent(java.lang.Class<E> eventClass, java.util.function.BiFunction<S,E,State> handler)
Match any event which is an instance ofE
or a subtype ofE
.<E extends Event>
EventHandlerBuilderByState<S,State,Event>onEvent(java.lang.Class<E> eventClass, java.util.function.Function<E,State> handler)
Match any event which is an instance ofE
or a subtype ofE
.<E extends Event>
EventHandlerBuilderByState<S,State,Event>onEvent(java.lang.Class<E> eventClass, java.util.function.Supplier<State> handler)
Match any event which is an instance ofE
or a subtype ofE
.<S2 extends State>
EventHandlerBuilderByState<S2,State,Event>orElse(EventHandlerBuilderByState<S2,State,Event> other)
Compose this builder with another builder.
-
-
-
Method Detail
-
builder
public static <S extends State,State,Event> EventHandlerBuilderByState<S,State,Event> builder(java.lang.Class<S> stateClass)
- Parameters:
stateClass
- The handlers defined by this builder are used when the state is an instance of thestateClass
- Returns:
- A new, mutable, EventHandlerBuilderByState
-
builder
public static <State,Event> EventHandlerBuilderByState<State,State,Event> builder(java.util.function.Predicate<State> statePredicate)
- Parameters:
statePredicate
- The handlers defined by this builder are used when thestatePredicate
istrue
, useful for example when state type is an Optional- Returns:
- A new, mutable, EventHandlerBuilderByState
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State,Event> onEvent(java.lang.Class<E> eventClass, java.util.function.BiFunction<S,E,State> handler)
Match any event which is an instance ofE
or a subtype ofE
.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.
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State,Event> onEvent(java.lang.Class<E> eventClass, java.util.function.Function<E,State> handler)
Match any event which is an instance ofE
or a subtype ofE
.Use this when then
State
is not needed in thehandler
, otherwise there is an overloaded method that pass the state in aBiFunction
.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.
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State,Event> onEvent(java.lang.Class<E> eventClass, java.util.function.Supplier<State> handler)
Match any event which is an instance ofE
or a subtype ofE
.Use this when then
State
and theEvent
are not needed in thehandler
.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.
-
onAnyEvent
public EventHandler<State,Event> onAnyEvent(java.util.function.BiFunction<State,Event,State> handler)
Match any event.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
onAnyEvent(java.util.function.BiFunction<State,Event,State>)
as it will match any event. This method builds and returns the event handler since this will not let through any states to subsequent match statements.- Returns:
- An EventHandler from the appended states.
-
onAnyEvent
public EventHandler<State,Event> onAnyEvent(java.util.function.Function<Event,State> handler)
Match any event.Use this when then
State
is not needed in thehandler
, otherwise there is an overloaded method that pass the state in aBiFunction
.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
onAnyEvent(java.util.function.BiFunction<State,Event,State>)
as it will match any event. This method builds and returns the event handler since this will not let through any states to subsequent match statements.- Returns:
- An EventHandler from the appended states.
-
orElse
public <S2 extends State> EventHandlerBuilderByState<S2,State,Event> orElse(EventHandlerBuilderByState<S2,State,Event> other)
Compose this builder with another builder. The handlers in this builder will be tried first followed by the handlers inother
.
-
build
public EventHandler<State,Event> build()
Builds and returns a handler from the appended states. The returnedEventHandler
will throw aMatchError
if applied to an event that has no defined case.
-
-