Connor Doyle
Connor Doyle

Reputation: 1912

Scanning for Akka Actors

I have a node which may be running multiple instances of a server (Akka remote actor). I would like clients to be able to scan a range of ports on a given node looking for live servers.

I wrote this method in my client actor:

  private def scanHost(serverHost: String) = {
    val initialPort = 36627
    val portsToScan = (initialPort until initialPort + 32).toList
    val tries = portsToScan map {
      port  ⇒ remote.actorFor("EnMAS-service", serverHost, port) ? Discovery
    }
    val replies = tries filter { future  ⇒ {
      try { 
        future.get match {
          case reply: DiscoveryReply  ⇒ true
          case _  ⇒ false
        }
      }
      catch { case _  ⇒ false }
    }}
    ClientManager.ScanResult(replies map {_.get.asInstanceOf[DiscoveryReply]})
  }

I am wondering, is there a more idiomatic way to get this done? I couldn't find much on this, although I imagine this use case is fairly common.

Upvotes: 1

Views: 450

Answers (1)

Viktor Klang
Viktor Klang

Reputation: 26579

Sounds like you're after a cluster. Until Akka 2.1 ships (with built in cluster support), you can use something like ZooKeeper or JGroups or otherwise to have nodes register when they start and deregister when they leave (or timeout)

Upvotes: 3

Related Questions