Java 类akka.actor.AllForOneStrategy 实例源码

项目:javactor    文件:JavactorUntypedActor.java   
@Override
public SupervisorStrategy supervisorStrategy()
{
    SupervisorStrategyInfo info = javactorInfoByJavactorType
        .get(javactor.getClass()).getSupervisorStrategyInfo().getInfo();
    Duration withinDuration = toDuration(info.getTimeRange(), info.getTimeUnit());
    final int maxNumRetries = info.getMaxNumRetries();
    final boolean loggingEnabled = info.isLoggingEnabled();
    return info.getType().equals(SupervisorStrategyType.ONE_FOR_ONE) ?
        new OneForOneStrategy(maxNumRetries, 
            withinDuration,
            myDecider(),
            loggingEnabled 
            ) :
        new AllForOneStrategy(maxNumRetries, 
            withinDuration,
            myDecider(),
            loggingEnabled 
            );
}
项目:intro_to_reactive    文件:AllForOneParentActor.java   
@Override
public SupervisorStrategy supervisorStrategy() {
    return new AllForOneStrategy(10, Duration.create(1, TimeUnit.HOURS),
      new Function<Throwable, Directive>() {
          @Override
          public Directive apply(Throwable param) throws Exception {
              if (param instanceof IllegalArgumentException) return escalate();
              if (param instanceof ArithmeticException) return escalate();
              if (param instanceof NullPointerException) return escalate();
              else return stop();
          }
      }
   );
}
项目:intro_to_reactive    文件:OneForOneParentActor.java   
@Override
public SupervisorStrategy supervisorStrategy() {
    return new AllForOneStrategy(10, Duration.create(1, TimeUnit.HOURS),
            new Function<Throwable, SupervisorStrategy.Directive>() {
                @Override
                public SupervisorStrategy.Directive apply(Throwable param) throws Exception {
                    if (param instanceof IllegalArgumentException) return escalate();
                    if (param instanceof ArithmeticException) return escalate();
                    if (param instanceof NullPointerException) return escalate();
                    else return stop();
                }
            }
    );
}
项目:intro_to_reactive    文件:AllForOneGrandparentActor.java   
@Override
public SupervisorStrategy supervisorStrategy() {
    return new AllForOneStrategy(10, Duration.create(1, TimeUnit.HOURS),
            new Function<Throwable, SupervisorStrategy.Directive>() {
                @Override
                public SupervisorStrategy.Directive apply(Throwable param) throws Exception {
                    if (param instanceof IllegalArgumentException) return SupervisorStrategy.stop();
                    if (param instanceof ArithmeticException) return SupervisorStrategy.resume();
                    if (param instanceof NullPointerException) return SupervisorStrategy.restart();
                    else return SupervisorStrategy.escalate();
                }
            }
    );
}
项目:javactor    文件:JavactorUntypedActorTest.java   
@Test
public void test_sup_strategy_all_for_one_type() throws Throwable
{
    javactor = new AllForOneTestJavactor();
    final Props props = Props.create(new MyCreator(javactor));
    final TestActorRef<JavactorUntypedActor> ref = TestActorRef.create(system, props,
        "testA");
    final SupervisorStrategy supervisorStrategy = ref.underlyingActor().supervisorStrategy();
    assertTrue(supervisorStrategy instanceof AllForOneStrategy);
    AllForOneStrategy afo = (AllForOneStrategy)supervisorStrategy;
    assertEquals(10, afo.maxNrOfRetries());
    assertEquals(Duration.create("1 minute"), afo.withinTimeRange());
}
项目:karajan    文件:CustomSupervisorStrategy.java   
public static final SupervisorStrategy defaultStrategy() {
final ExceptionElement exceptionElement=matchExceptionToErrorHadling();
Function<Throwable, Directive> behavior=new Function<Throwable, Directive>(){
    @Override
    public Directive apply(Throwable t) throws Exception {
        ProcessorException e=(ProcessorException)t;
        if ( exceptionElement.getStategy()==ErrorStrategy.ONE && exceptionElement.getAction()==Action.SKIP) {

            stepexcmanager.tell(new MasterWorkerProtocol.WorkFailed(e.getWorkerId(), e.getWorkId()), ActorRef.noSender());
           return SupervisorStrategy.resume();
        }
        else if( exceptionElement.getStategy()==ErrorStrategy.ONE && exceptionElement.getAction()==Action.RETRY){

            if(currentrestrart < exceptionElement.getTrynumber()-1){
                executor.tell(new StepExecutionManager.Work(UUID.randomUUID().toString(),3), stepexcmanager);
                return SupervisorStrategy.restart();
            }else{
                stepexcmanager.tell(new MasterWorkerProtocol.WorkFailed(e.getWorkerId(), e.getWorkId()), ActorRef.noSender());
                return SupervisorStrategy.resume();
            }
        }
        else if(exceptionElement.getStategy()==ErrorStrategy.ALL && exceptionElement.getAction()==Action.SKIP){
             stepexcmanager.tell(new OrchestratorMasterProtocol.BatchFail(Action.SKIP), ActorRef.noSender());
             return SupervisorStrategy.resume();
        }
        else if(exceptionElement.getStategy()==ErrorStrategy.ALL && exceptionElement.getAction()==Action.RETRY){
             stepexcmanager.tell(new OrchestratorMasterProtocol.BatchFail(Action.RETRY), ActorRef.noSender());
        }
        return SupervisorStrategy.escalate();
    }

};

if(exceptionElement!=null){
    //AllForOneStrategy: The strategy is applied to all the children
    if(exceptionElement.getStategy()==ErrorStrategy.ALL){
        return new AllForOneStrategy(exceptionElement.getTrynumber(),Duration.create(5,TimeUnit.SECONDS),behavior);
    }
    //OneForOneStrategy: The strategy is applied to only the children that fail
    else if(exceptionElement.getStategy()==ErrorStrategy.ONE){
    return new OneForOneStrategy(exceptionElement.getTrynumber(), Duration.create(5,TimeUnit.SECONDS),behavior);
    }
}

// The Manager does not know how to handle this error
return SupervisorStrategy.defaultStrategy();

}
项目:geo-publisher    文件:ProvisioningSystem.java   
@Override
public Directive apply(Throwable t) throws Exception {          
    return AllForOneStrategy.restart();
}
项目:geo-publisher    文件:ProvisioningManager.java   
@Override
public Directive apply(Throwable t) throws Exception {          
    return AllForOneStrategy.escalate();
}
项目:geo-publisher    文件:InfoCollector.java   
@Override
public Directive apply(Throwable t) throws Exception {          
    return AllForOneStrategy.escalate();
}