Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actor name is not unique - AKKA

I'm using Akka 2.10 with JAVA.

I have a method that takes an Actor reference for me - or create one if there it wasnt before - but some times when I try to create one I receive the following exception:

akka.actor.InvalidActorNameException: actor name [<ActorName>] is not unique!
    at akka.actor.dungeon.ChildrenContainer$NormalChildrenContainer.reserve(ChildrenContainer.scala:130)
    at akka.actor.dungeon.Children$class.reserveChild(Children.scala:77)
    at akka.actor.ActorCell.reserveChild(ActorCell.scala:369)
    at akka.actor.dungeon.Children$class.makeChild(Children.scala:202)
    at akka.actor.dungeon.Children$class.attachChild(Children.scala:42)
    at akka.actor.ActorCell.attachChild(ActorCell.scala:369)
    at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:552)

Of course, I know, the exception is very clear: I'm trying to create more than one actor with the same identifier, but I just do this when I can't find actor's ref. In time:

private static ActorRef getActor(String id,Class actor) throws Exception{
    ActorSelection sel = system.actorSelection(system.child(id));
    Timeout t = new Timeout(4, TimeUnit.SECONDS);
    AskableActorSelection asker = new AskableActorSelection(sel);
    scala.concurrent.Future<Object> fut = asker.ask(new Identify(1), t);
    ActorRef actorClient = null;
    try{
        //Try to get an Actor reference
        ActorIdentity ident = (ActorIdentity)Await.result(fut, t.duration());
        actorClient = ident.getRef();
    } catch(Exception e){
        System.out.println("Error:"+id);
    } finally{
        //IF I dont found create a new One
        if(actorClient==null){
            actorClient = system.actorOf(Props.create(actor),id);
            //THROWS ME AN EXCEPTION
        }
    }
    return actorClient;
}

I wait 4 seconds without an answer... so i create a new one.

I searched the internet through a solution for my case, but without success...

Can anyone help me to solve this problem?

Thanks a lot!

like image 541
Elvis Oliveira Avatar asked Jan 28 '15 16:01

Elvis Oliveira


1 Answers

According to the documentation you should not re-use actor paths, even if the actor has died. My guess would be that you've created an actor with that name previously, it died and now can't be found via the actor selection mechanism. In trying to create a new actor with that name you're running into this exception.

like image 59
Gavin Schulz Avatar answered Sep 21 '22 12:09

Gavin Schulz