All my actors inherit from BaseActor and can create children actor with 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()
}
}
}
When an actor /user/dad create 2 children actors using registerActor() however 2 supervisors are created
/user/dad/supervisor_foo/foo
/user/dad/supervisor_bar/bar
How can I reuse the same supervisor to supervise both foo and bar ?
/user/dad/supervisor/foo
/user/dad/supervisor/bar
BackoffSupervisors only support a single (direct) child.If you want to re-use a
BackoffSupervisorthe only way is by introducing another supervisor as its child:Where
/user/dad/backoffsupervisoris aBackoffSupervisorand where/user/dad/backoffsupervisor/supervisoris an actor that watches its children (fooandbar) and stops when either child stops, cascading the failure to the backoff supervisor.