Package groovy.concurrent
Interface StatefulHandler<S,T>
- Type Parameters:
S- the state typeT- 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.
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
-
Method Details
-
apply
Processes a single message and returns the new state.- Parameters:
ctx- the actor contextstate- the current statemessage- the incoming message- Returns:
- the new state
-