scala - How to get Akka actor by name as an ActorRef? -
in akka can create actor follows.
akka.system(app).actorof(props(classof[unzipactor]), name="somename")
then in different class, how can actor?
i can actorselection
lazy val unzip: actorselection = akka.system.actorselection("user/" + "somename")
however, actorselection
not want; want actorref
. how can actorref
?
i want have actorref
since wish schedule call actorref
using scheduler.
akka.system(app).scheduler.schedule( 5 seconds, 60 seconds, mustbeactorref, messagecaseclass())
you can use method resolveone
on actorselection actorref asynchronously.
implicit val timeout = timeout(finiteduration(1, timeunit.seconds)) akka.system.actorselection("user/" + "somename").resolveone().oncomplete { case success(actorref) => // logic actorref case failure(ex) => logger.warn("user/" + "somename" + " not exist") }
ref : http://doc.akka.io/api/akka/2.3.6/index.html#akka.actor.actorselection
Comments
Post a Comment