Interface StatefulHandler<S,T>

Type Parameters:
S - the state type
T - the message type
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface StatefulHandler<S,T>
Context-aware handler for stateful actors. Receives the actor context, the current state, and the incoming message; returns the new state, which is also bound to the reply for Actor.sendAndGet(T) callers.

To stop the actor from inside the handler, call ctx.self().stop().

Known limitation around behaviour swaps. If a handler calls ctx.become(...) with a StatefulHandler whose S type is incompatible with the actor's current state, the ClassCastException surfaces on the next dispatch — not at the become call site. The actor's S is erased at construction and cannot be re-checked at the swap site; see ActorContext.become(StatefulHandler) for the full discussion.

Since:
6.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(ActorContext<T> ctx, S state, T message)
    Processes a single message and returns the new state.
  • Method Details

    • apply

      S apply(ActorContext<T> ctx, S state, T message)
      Processes a single message and returns the new state.
      Parameters:
      ctx - the actor context
      state - the current state
      message - the incoming message
      Returns:
      the new state