Package: groovy.concurrent

## [Java] Interface StatefulHandler<S, T>

-     @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 callers.

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

  Known limitation around behaviour swaps. If a handler calls ActorContext.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 for the full discussion.

  Type Parameters:
    `S` - the state type
    `T` - the message type
  See Also:
    Actor.stateful
  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public S` | `apply(ActorContext<T> ctx, S state, T message)` Processes a single message and returns the new state.

- - ### Method Detail

    - #### public 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