How to know if a certain actor does not exist

Asked

Viewed 62 times

2

I’m working with Akka/Java

A reference to an actor who doesn’t exist, simply nay returns exception and/or do 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 path of Register is akka://default/ is not complete.

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

How should I proceed?

1 answer

0


use the solving function 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
  })
  • Perfect your answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.