如何在主管策略重新启动actor之后重新发送消息

Sim*_*mon 6 akka

我有父母演员(A)和两个儿童演员(B).我在A中制定了一个主管策略,因此如果B中发生特定异常,B将重新启动.

如何重新发送导致B到B异常的消息?

Sim*_*mon 11

我在B中所做的是在preRestart中再次向B发送消息,请参阅下面的代码.

  @Override
  public void preRestart(final Throwable reason, final scala.Option<Object> message) throws Exception
  {
    getSelf().tell(message.get(), getSender());
  };
Run Code Online (Sandbox Code Playgroud)

为了确保我不以无限循环结束,我在A中配置监督策略如下:

  private final SupervisorStrategy strategy = new OneForOneStrategy(3, Duration.Inf(),
      new Function<Throwable, SupervisorStrategy.Directive>()
  {   
    @Override
    public Directive apply(final Throwable t) throws Exception
    {
      if (t instanceof SpecificException)
      {
        return SupervisorStrategy.restart();
      }
      return SupervisorStrategy.escalate();
    }
  });    
Run Code Online (Sandbox Code Playgroud)

这应该是保证,有问题的信息只会重发三次.如果这是一个好的做法或者让我联系到更好的解决方案,有人可以给我一个建议吗?