I have built a proper actor hierarchy for my Scala/Java application that is relies mostly on fire-forget semantics. I am now faced with the need to pass unique mutable objects atomically between actors. In particular, I have three actors, A, B and C:
A
/ \
B C
B and C both have their own Map of unique Objects and do not know about each other. At some point in time, B will decide that it needs to get rid of object O. I am looking for a mechanism that allows for object O to be added to C's Map and removed from B's Map atomically
B does not decide that it is C that will receive object O: all it does at first is sending a disposal request to actor A. Actor A can allow or refuse the disposal request from B and from there introduce or not C to actor B for them to conclude the transaction autonomously and atomically.
EDIT
My original question is ill-labeled and confused. In my system messages are immutable: I send UUIDs between actors, not refs to objects. These UUIDs are the keys to a private per-actor map of mutable objects. The usage of objects held by both B and C in their private map are is meant to be mutually exclusive at any given point in time.
It is trivial for me to go one step further and make sure no mutable object is ever shared between B and C, that is, to make sure key K in B's map and key K in C's map point to different private mutable objects (say Ob and Oc) having the same UUID.
One goal is to avoid doing calculations on object Ob in B and Oc in C at the same time. This is not really a problem in itself (I don't mind wasting a few CPU cycles once in a while during a transition from actor B to actor C), but it becomes a problem since actors B and C report their simulation results to a 3rd party client that we can call D.
D does not know about the relationship between A, B and C, and it could therefore receive results from B and C about the same UUID, not being able to tell which one it should listen to. Due to the nature of the simulation, these results could be different and conflicting. Of course, actor B could stop simulating object Ob and send a message to actor C telling it to start the simulation on object Oc. That would prevent client D to receive messages from both B and C about the same object, but there would be a time frame during which this UUID could be absent from the simulation altogether. Perhaps this is not very important for my application but I still have to verify this. The ideal for me would be a synchronized switch of actor for a UUID.