【发布时间】:2014-03-16 22:17:56
【问题描述】:
我有三个远程 Akka Actor:A、B 和 C。A 向 B 发送消息,B 保存 A 的引用(见下文)。另外,我需要 B 将 A 的引用发送给 C。我该怎么做? B 的 Java 代码如下所示:
public class B extends UntypedActor {
//---------------------------------------------------------------
/**
* {@inheritDoc}
*/
@Override
public void onReceive(Object object) throws Exception {
if (refA == null) {
refA = getSender();
}
// how do I send refA to C???
refC.tell(refA, getSelf()); // <== like this?
}
// set during onReceive
private ActorRef refA = null;
// initialized in constructor
private final ActorRef refC;
}
我刚刚检查了一下,ActorRef 是 Serializable 所以理论上我上面提出的解决方案应该可以工作,但是有没有不同的/官方的/更清洁的方法呢?
【问题讨论】: