I am working on some logic which involves shutting down idle actors. However these actors are pooled actors, which means the ReceiveTimeout
message is sent to all the actors in the pool.
The problem I'm running into is that if I have 5 actors in the pool, when the pool receives a message, only one of them has their timeout reset. The rest 4, since they did not receive a message are still on the original TimeOut
clock, which makes sense as per the framework. But for my usecase I want it such that if one of the actors in the pool receives a message, the timeout is reset for all. How can I accomplish this? One crude way I have thought of is that as soon as one actor in the pool receives a message, it sends a heartbeat to the rest of the actors in the pool. But not sure how to achieve this in Akka.
My actor is started in this manner -
Props.create(ActorA.class, () -> new ActorA()).withRouter(new SmallestMailboxPool(poolSize));
CodePudding user response:
By pooled actors I am assuming you mean a router with pool characteristics? Presuming that, look at broadcast messages under the specially handled messages handling section of the docs.
Set the receiveTimeout on the router and then send a broadcast message to the workers in the handler for that timeout in the router.