如何检查Akka演员是否存在(akka 2.2)?
我有一个java对象,它不是一个actor,它使用actorSelection(Path)从actor系统中选择actor。有可能,选定的参与者不存在于系统中。
在Java Api中,ask()不存在用于ActorSelection,因此我无法向选择Actor发送和识别消息并使用响应的发送者。
我试图通过演员选择将消息发送给演员,然后对死信做出反应来解决这个问题。但是我没有得到任何死信。
如何使用 ActorSelection 检查 Actor 是否处于活动状态或不存在?
ActorSystem system = ActorSystem.create("test");
//create test actor
system.actorOf(Props.create(TestActor.class), "testActor");
//add dead letter listener to the system
ActorRef eventBusActor = asys.actorOf(Props.create(EventBusActor.class), "eventbusactor");
system.eventStream().subscribe(eventBusActor, DeadLetter.class);
//This works. The test actor receives the message
ActorSelection a1 = asys.actorSelection("/user/testActor");
a1.tell("hello", ActorRef.noSender());
//This does not work and does not send dead letters
ActorSelection a2 = asys.actorSelection("/user/doesnotexist");
a2.tell("hello", ActorRef.noSender());
//Does not compile, because ask needs an ActorRef as first argument
ActorSelection a3 = asys.actorSelection("/user/test");
Future f = Patterns.ask(a3, new Identify(), 1000);