我正在尝试监督 Akka Actor,更具体地说是使用ClusterSingletonManager
. 我正在尝试对异常、日志和 Actor 的生命周期进行更多控制。
不幸的是,在实施解决方案后,我让 Singleton Actor 抛出异常,但日志中没有显示任何内容,Actor 或 Cluster 也没有关闭。
我的实现如下:
object SingletonSupervisor {
case class CreateSingleton(p: Props, name: String)
}
class SingletonSupervisor extends Actor with ActorLogging {
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 0, withinTimeRange = 1.minute) {
case x: ActorInitializationException =>
log.error(s"Actor=<${x.getActor}> trowed an exception=<${x.getCause}> with message=<${x.getMessage}>")
Stop
case x: ActorKilledException => Stop
case x: DeathPactException => Stop
case x: Exception =>
log.error(s"Some actor threw an exception=<${x.getCause}> with message=<${x.getMessage}>, trace=<${x.getStackTrace}>")
Escalate
}
def receive = {
case CreateSingleton(p: Props, name: String) =>
sender() ! context.actorOf(p)
context.actorOf(ClusterSingletonManager.props(
singletonProps = p,
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(context.system)),
name = name)
}
}
那么,是否有可能监督 Cluster Singlegon?如果可能的话,我应该如何解决这个问题?