Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if remote Akka actor is available

Tags:

scala

akka

How can I check if a remote actor, for which I have obtained an actorRef via actorFor, is alive? Any reference to documentation would be appreciated. I am using Akka from Scala.

I've seen reference to supervisors and deathwatch, but don't really feel my use-case needs such heavy machinery. I just want to have my client check if the master is up using a known path, and if it is send a message introducing itself. If the master is not up, then it should wait for a bit then retry.

Update 2: Suggestions are that I just use a ping-pong ask test to see if it's alive. I understand this to be something like

implicit val timeout = Timeout(5 seconds)
val future = actor ? AreYouAlive
try{
    Await.result(future, timeout.duration)
}catch{
    case e:AskTimeoutException => println("It's not there: "+e)
}

I think I've been confused by the presence of exceptions in the logs, which remain there now. E.g.

  • Error: java.net.ConnectException:Connection refused
  • Error: java.nio.channels.ClosedChannelException:null

Perhaps this is just how it works and I must accept the errors/warning in the logs rather than try to protect against them?

like image 712
Pengin Avatar asked May 22 '12 15:05

Pengin


2 Answers

Just send it messages. Its machine could become unreachable the nanosecond after you sent your message anyway. IF you don't get any reply, it is most likely dead. There's a large chapter on this in the docs: http://doc.akka.io/docs/akka/2.0.1/general/message-send-semantics.html

like image 99
Viktor Klang Avatar answered Sep 18 '22 06:09

Viktor Klang


You should never assume that the network is available. Our architect here always says that there are two key concepts that come into play in distributed system design.

They are:

  • Timeout
  • Retry

Messages should 'timeout' if they don't make it after x period of time and then you can retry the message. With timeout you don't have to worry about the specific error - only that message response has failed. For high levels of availability you may want to consider using tools such as zookeeper to handle clustering/availability monitoring. See leader election here for example: http://zookeeper.apache.org/doc/trunk/recipes.html

like image 40
JasonG Avatar answered Sep 22 '22 06:09

JasonG