@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.
S - the state typeT - the message type| 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. |
Processes a single message and returns the new state.
ctx - the actor contextstate - the current statemessage - the incoming message