How to get the port of a remote actor when it was dynamically set?

142 views Asked by At

I'm new to remote actors and I'm facing a problem. I need to set the port of my actors dynamically (or I have some problems with addresses already in use in my tests) but I don't find how to get the port that has been set.

I work with Play! scala. I thought I could get the port by a Play! controller like this (although it doesn't seem to be the proper way):

def remoteActorsPort = Action.async { implicit request =>
  implicit val timeout: akka.util.Timeout = 3.seconds
  val saveEventActor = actorSystem.actorSelection("/user/save-event-actor")
  saveEventActor ? WhatMyPort() map { maybePort =>
    maybePort.asInstanceOf[Option[Int]] match {
      case Some(port) => Ok(Json.toJson(port))
      case _ => NotFound
    }
  }
}

And in my actor:

case whatMyPort: WhatMyPort => sender ! self.path.address.port

But self.path.address.port returns None.

How can I proceed to get the port of a remote actor when it has been dynamically set?

0

There are 0 answers