我所有的演员都继承自BaseActor
并可以创建子演员registerActor()
abstract class BaseActor() : AbstractLoggingActor() {
protected fun registerActor(childProps: Props, name: String): ActorRef {
val child = context.child(name)
val supervisorProps = BackoffSupervisor.props(
BackoffOpts.onFailure(
childProps,
name,
java.time.Duration.ofSeconds(1),
java.time.Duration.ofSeconds(30),
0.2 // adds 20% "noise" to vary the intervals slightly
).withAutoReset(FiniteDuration(20, TimeUnit.SECONDS))
)
return if (child.isEmpty) {
context.actorOf(supervisorProps, "supervisor_$name").also { addChildRoutee(it) }
} else {
child.get()
}
}
}
当一个演员/user/dad
创建 2 个子演员时,registerActor()
但是创建了 2 个主管
/user/dad/supervisor_foo/foo
/user/dad/supervisor_bar/bar
如何重用同一个主管来监督foo
和bar
?
/user/dad/supervisor/foo
/user/dad/supervisor/bar