Class EventHandlerBuilderByState<S extends State,State,Event>

java.lang.Object
org.apache.pekko.persistence.typed.javadsl.EventHandlerBuilderByState<S,State,Event>

public final class EventHandlerBuilderByState<S extends State,State,Event> extends Object
  • Constructor Details

    • EventHandlerBuilderByState

      public EventHandlerBuilderByState(Class<S> stateClass, Predicate<S> statePredicate)
  • Method Details

    • builder

      public static <S extends State, State, Event> EventHandlerBuilderByState<S,State,Event> builder(Class<S> stateClass)
      Parameters:
      stateClass - The handlers defined by this builder are used when the state is an instance of the stateClass
      Returns:
      A new, mutable, EventHandlerBuilderByState
    • builder

      public static <State, Event> EventHandlerBuilderByState<State,State,Event> builder(Predicate<State> statePredicate)
      Parameters:
      statePredicate - The handlers defined by this builder are used when the statePredicate is true, useful for example when state type is an Optional
      Returns:
      A new, mutable, EventHandlerBuilderByState
    • onEvent

      public <E extends Event> EventHandlerBuilderByState<S,State,Event> onEvent(Class<E> eventClass, BiFunction<S,E,State> handler)
      Match any event which is an instance of E or a subtype of E.

      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(Class<E> eventClass, Function<E,State> handler)
      Match any event which is an instance of E or a subtype of E.

      Use this when then State is not needed in the handler, otherwise there is an overloaded method that pass the state in a BiFunction.

      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(Class<E> eventClass, Supplier<State> handler)
      Match any event which is an instance of E or a subtype of E.

      Use this when then State and the Event are not needed in the handler.

      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(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(Function<Event,State> handler)
      Match any event.

      Use this when then State is not needed in the handler, otherwise there is an overloaded method that pass the state in a BiFunction.

      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

      Compose this builder with another builder. The handlers in this builder will be tried first followed by the handlers in other.
    • build

      public EventHandler<State,Event> build()
      Builds and returns a handler from the appended states. The returned EventHandler will throw a MatchError if applied to an event that has no defined case.