1 つの親に対して 1 つの子アクターを作成しています。私の子アクターはいくつかのビジネス ロジックを実行し、値を scala Future に返します。親にメッセージを送信Future
すると、将来のメッセージをキャッチできません。以下は私のコードです:
子役
public class FetchDevicesIds extends AbstractActor {
private final LoggingAdapter LOG = Logging.getLogger(context().system(), this);
private final ActorRef parent = context().parent();
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder.
match(String.class, msg -> {
final ExecutionContext ec = context().dispatcher();
Future<DevicesIds> future = Futures.future(() -> new DevicesIds(new ArrayList<>()), ec);
future.onFailure(futureFailureHandler(), ec);
System.out.println("************************************ : "+parent);
pipe(future, ec).to(parent);
}).
matchAny(msg -> LOG.info("unknown message: "+ msg)).
build();
}
private OnFailure futureFailureHandler(){
return new OnFailure() {
@Override
public void onFailure(Throwable failure) throws Throwable {
if(failure.getCause() instanceof DevicesNotFound){
self().tell("-----------------", ActorRef.noSender());
}
}
};
}}
親アクター
public class NotificationSupervisor extends AbstractActor {
private final LoggingAdapter LOG = Logging.getLogger(context().system(), this);
private final ActorContext context = context();
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder.
match(String.class, msg -> {
ActorRef fetchDeviceIds = context.actorOf(Props.create(FetchDevicesIds.class), "fetch-devices-ids");
fetchDeviceIds.tell("fetch-ids", self());
}).
match(DevicesIds.class, ids -> System.out.println("&&&&&&&&&&&&& I GOT IT")).
matchAny(msg -> LOG.info("unknown message: "+ msg)).
build();
}
ログ
[INFO] [08/21/2016 13:04:10.776] [ActorLifeCycleTest-akka.actor.default-dispatcher-4] [akka://ActorLifeCycleTest/user/notification-supervisor]
Message [java.lang.Integer] from Actor[akka://ActorLifeCycleTest/deadLetters] to TestActor[akka://ActorLifeCycleTest/user/notification-supervisor] was not delivered. [1] dead letters encountered.
This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'
アップデート
将来の代わりに親に送信しようとしていますtell
が、それでも親はメッセージを受け取りません。以下は私の変更です:
parent.tell(23, ActorRef.noSender()); //replace pipe(future, ec).to(parent);
親matchAny(msg -> {System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");LOG.info("unknown message: "+ msg);})
ケースがこのメッセージを処理します。しかし、何も起こりません。
更新 2
future.onFailure(futureFailureHandler(), ec);
私の調査によると、ステートメントをコメントアウトすると、parent.tell(23, ActorRef.noSender());
正常に実行されます。なぜこれが起こるのかまだわかりません。
私の要件は、将来のメッセージを親アクターに送信し、akka アクター システムのフォールト トレランスのために将来の障害を処理することです。