The name of the actor is not unique - AKKA

I am using Akka 2.10 with JAVA.

I have a method that links to an Actor link for me - or create one if it wasnโ€™t before - but sometimes, when I try to create one, I get 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 that the exception is very clear: I try to create more than one actor with the same identifier, but I just do it when I can not find the link to the actor. With 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 business, but to no avail ...

Can someone help me solve this problem?

Thank you so much!

+7
java actor akka playframework
source share
1 answer

According to the documentation, you should not reuse the paths for the actors, even if the actor has died. I assume that you created an actor with that name before, he died and now cannot be found through the actor selection mechanism. When you try to create a new actor with this name, you will encounter this exception.

+6
source share

All Articles