How to tell if a certain Actor does not exist

2

I'm working with Akka / Java

A reference to an actor that does not exist, simply does returns exception and / or does not know how to capture information that the actor does not exist in the actor system.

ActorSelection register = null;
register = actorSystem.actorSelection("akka://default/user/ATOR-NAO-EXISTE");

I also noticed that the register path is akka://default/ is not complete.

This actor does not exist, but also does not generate errors.

How do I proceed?

    
asked by anonymous 07.08.2015 / 21:13

1 answer

0

use the resolveOne function of ActorSelection

java:


final ExecutionContext ec = system.dispatcher();

ActorSelection register = system.actorSelection("akka://default/user/ATOR-NAO-EXISTE");
Future future = register.resolveOne()
future.onSuccess(new OnSuccess() {
  public void onSuccess(ActorRef actor) {
    // the actor reference
  }
}, ec);

future.onFailure(new OnFailure() {
  public void onFailure(Throwable failure) {
    if (failure instanceof ActorNotFound) {
      // actor not found
    }
  }
}, ec);

scala:


val register = system.actorSelection("akka://default/user/ATOR-NAO-EXISTE");
val future  = register.resolveOne()
future.onSuccess({
    case actor: ActorRef => // the actor reference
  })

future.onFailure({
    case e: ActorNotFound => // actor not found
    case _ => // anything else
  })
    
07.08.2015 / 22:06