问题
I have a remote actor (client) which is registering with another remote actor (server) and then later deregistering (with a shutdown hook). However, although the server picks up the de-registration, the actual sender
property is a different Channel object; so in my server logs I have:
Registered new client [scala.actors.Channel@158e282]; supporting 1 clients
De-registered client [scala.actors.Channel@1caf0b6]; supporting 1 clients
How can I determine (on the server side) that this was the same client actor which originally registered with me? Obviously I could imbue each client with its own UUID
but I wonder whether there is an easier way?
回答1:
From a discussion on the scala users' mailing list, it seems that this is not immediately possible without using some alternative kind of client identifier (like UUID
). If you send the self
reference from the client in your registration object, you will get a ObjectNotSerializable
error.
回答2:
Explicitly add the sender to your message. Use RemoteActor.select to get a scala.actors.remote.Proxy. Use its toString method to identify the sender.
来源:https://stackoverflow.com/questions/1058450/how-can-i-identify-a-remote-actor