演员姓名不是唯一的 - AKKA

Elv*_*ira 9 java actor akka playframework

我正在使用Akka 2.10和JAVA.

我有一个方法,为我提供一个Actor引用 - 或者如果之前没有它,则创建一个 - 但有时当我尝试创建一个时,我收到以下异常:

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)
Run Code Online (Sandbox Code Playgroud)

当然,我知道,异常非常明确:我正在尝试使用相同的标识符创建多个actor,但是当我找不到actor的ref时,我就这样做了.及时:

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;
}
Run Code Online (Sandbox Code Playgroud)

我等了4秒没有答案......所以我创建了一个新的.

我通过解决方案搜索了我的案例,但没有成功......

任何人都可以帮我解决这个问题吗?

非常感谢!

Gav*_*ulz 7

根据文档,你不应该重复使用actor路径,即使演员已经死亡.我的猜测是你之前创造了一个具有该名称的演员,它已经死了,现在无法通过演员选择机制找到.在尝试使用该名称创建一个新actor时,您遇到了这个异常.