I am creating one child actor for one parent. My child actor perform some business logic and return value to scala Future. When i send Future
message to my parent, i am unable to catch my future message. Following is my code:
Child Actor
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());
}
}
};
}}
Parent Actor
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();
}
Logs
[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'
Update
I am trying to send tell
to parent instead of future, but still parent not getting the message. Follwoing is my changes :
parent.tell(23, ActorRef.noSender()); //replace pipe(future, ec).to(parent);
expectd, parent matchAny(msg -> {System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");LOG.info("unknown message: "+ msg);})
case handle this message. But nothing happens.
Update 2
According to my investigation, when i comment out future.onFailure(futureFailureHandler(), ec);
statement, the parent.tell(23, ActorRef.noSender());
execute successfully. Still not getting why this happens.
My requirements are, send future message to parent actor and handle future failure for fault-tolerance in akka actor system.