With the Java API, something like this:
public class ComputeIntensiveChild extends AbstactActor {
private final ActorRef realParent;
public static Props create(ActorRef realParent) {
return Props.create(ComputeIntensiveChild.class, realParent);
}
public ComputeIntensiveChild(ActorRef realParent) {
this.realParent = realParent;
}
public Receive createReceive() {
...
}
}
This way you send the answer to realParent instead of getContext().getParent(). Even if there's a router between the child and realParent, the intended recipient gets the message.
BUT I'm not sure this isn't a premature optimization. Since there's a possibility of a router in the mix, that means the child is sending a response to a message it received. In that case, just
send the response to the sender -- routers always forward messages, preserving the original sender.