我有以下情况
Actor A
收到请求并将工作委托给两个子代理ACtor b
和Actor c
。这两个角色都改变了对象的状态,但是父角色并不依赖于任何这些角色的结果
这是反模式吗?如何在不传递此对象的情况下分配负载?
答案 0 :(得分:0)
这是scala中的示例,但逻辑是相同的
class ParentActorA extends Actor {
val childActorB: ActorRef = _
val childActorC: ActorRef = _
def receive: Receive = {
case r: Request =>
childActorB ! Delegate(r)
childActorC ! Delegate(r)
case n: ChildNotification => //change local state based on this notification from child actor
}
}
class ChildActorA extends Actor {
def receive: Receive = {
case Delegate(r) => //do some work and notify parent with ChildNotification object
}
}