I have a chain of Akka actors K -> L -> M, where K sends messages to L, L sends message to M, and each can reply to its predecessor using the sender
of a received message.
My question is this: how can we safely unlink L from the chain, such that after the operation K sends messages directly to M, and M sees K as its sender
?
If each actor was stable and long-lived, I could work out how to tell K and M to talk to each other. L could hang around long enough to forward messages already in her mailbox until getting a signal that each of K and M was no longer talking to L.
However, K and M might also be thinking about unlinking themselves, and that's where everything gets hairy.
Is there a well-known protocol for making this work safely? So far I haven't found the right search terms.
I know that one alternative would be to freeze the system and copy the entire thing, minus L, into a new chain. However, I would like to implement a more real-time, less interrupted solution.
I've been thinking about some kind of lock exchange, in which K and M promise to not unlink themselves until L has finished unlinking and forwarding all messages. But any solution with the word "lock" seems awkward in an asynchronous solution, even though the actors wouldn't be fully locked (just delaying their own unlink operations until a convenient time).