Check if the sender of the participant was local or remote

I need to determine if the sender of the message was one of the local or remote members of the Akka cluster. Currently, the only way I have found for this is

def isLocal(sndr: ActorRef) = sndr.path.address.toString == context.system.toString

What is the best way?

I am using Akka 2.3

Update: To explain why I want to do this, in case there is a way to completely avoid the problem.

In each node, the router manages multiple participants to do the work. Actor workers send the results back to the local master actor and new assignments are assigned through the sender’s link. Master actors also periodically send results to leading actors of other nodes, ensuring that data is randomly “mixed” between masters on different nodes. In the case of data coming from a remote participant, the master recipient should not try to allocate a new job. This is essentially an implementation of the island mixing method.

+4
source share
2 answers

ActorSystem Extension (. Akka). , , .

, - . , , , , .

def receive = {
  case NonLocalResults(results) => // do something with non-local results
  case Results(...)             => // do something with local results
  ...
}
+2

Sender host protocol. empty akka , , hostname/ip akka.tcp

+1

All Articles