public void actorExists() throw ActorNotFound{
FiniteDuration duration = Duration.create(3, TimeUnit.SECONDS);
String actorPath = "akka://test/studentid";
Await.result(actorSystem.actorSelection(actorPath).resolveOne(new Timeout(duration)), duration);
return true;
}
此代码能够识别本地节点中的参与者,但不能识别集群中的参与者。如果本地节点中不存在任何actor,则抛出actor not found异常(如果存在),则返回true。
public void actorExists()throw ActorNotFound {FiniteDuration duration = Duration.create(3,TimeUnit.SECONDS);字符串actorPath =“ akka:// test / studentid”; Await.result(actorSystem ....
public boolean actorExists(String deviceId) throws Exception {
for (Member member : cluster.state().getMembers()) {
try {
String actorPath = member.address() + "/test/studentid";
FiniteDuration duration = Duration.create(3, TimeUnit.SECONDS);
Await.result(actorSystem.actorSelection(actorPath).resolveOne(new Timeout(duration)), duration);
} catch (ActorNotFound exception) {
continue;
}
return true;
}
throw new ActorNotFound(null);
}