【发布时间】:2017-09-22 01:03:01
【问题描述】:
我在 Akka-Java 中有以下问题。
我有一个父 Actor MainActor.class,这个父有 5 个子路由。以下是层次结构:
My App => Main Actor => [Child Route-1,Child-Route-2,..]
简单用例是将字符串输入解析为整数作为输出:
MyApp ===ask[string input]===> Main Actor ==route==> Child(parses to Integer) === integer result===> Main Actor ===result==> MyApp
这里是主角sn-p:
class MainActor extends UntypedActor {
Router router; {
// ...routes are configured here
}
public void onReceive(Object message) {
if (message instanceof String) {
router.route(message, self()); // route it to child
} else if (message instanceof Integer) {
// received from child, 'tell' this result to actual sender/parent i.e, MyApp
sender().tell(message, self());
} else unhandled(message);
}
}
Child Actor 除了将 String 解析为 Integer 并获取结果并通过 sender().tell(result,getContext().parent()) 将其发送回其发送者之外,什么都不做
问题
MainActor 正在将 child 发送的 Parsed 整数结果发送回 child 本身,而不是 MyApp。我还尝试将MainActor 中的sender() 替换为getContext().parent(),但仍然无效。
【问题讨论】: