Reusing Actor Paths

(George Soler) #1

I am learning Akka and I am trying to understand a statement I read in the docs about reusing actor paths-

‘When an actor is terminated, its reference will point to the dead letter mailbox, DeathWatch will publish its final transition and in general it is not expected to come back to life again… While it is possible to create an actor at a later time with an identical path, this is not good practice…’

I am modeling physical entities in a domain by mapping them to actors. The entities may appear and then disappear for seconds, hours, or days at a time, and may return any moment -or not. However, if they are gone for too long, their supervisor will terminate the corresponding actor. The actors need not be persistent in my system.

I am wondering then- if an entity re-appears and the same supervisor creates a new ActorRef instance from scratch which happens to have the same characteristics as the dead actor (since it’s the same entity), will it not automatically share the same logical and physical paths? What is the best practice in this situation? I hope I don’t need to synthesize a new logical path for every single such occurrence.

(Patrik Nordwall) #2

I don’t see a problem with that. You passivate the entities to free (memory) resources. That is what is supported with Cluster Sharding also.