本文整理汇总了Java中akka.actor.SupervisorStrategy.restart方法的典型用法代码示例。如果您正苦于以下问题:Java SupervisorStrategy.restart方法的具体用法?Java SupervisorStrategy.restart怎么用?Java SupervisorStrategy.restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类akka.actor.SupervisorStrategy
的用法示例。
在下文中一共展示了SupervisorStrategy.restart方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: supervisorStrategy
import akka.actor.SupervisorStrategy; //导入方法依赖的package包/类
@Override
public SupervisorStrategy supervisorStrategy() {
return new OneForOneStrategy(10, Duration.create(1, TimeUnit.MINUTES),
new Function<Throwable, SupervisorStrategy.Directive>() {
@Override
public SupervisorStrategy.Directive apply(Throwable param)
throws Exception {
if (param instanceof
IllegalArgumentException)
return SupervisorStrategy.restart();
if (param instanceof
ArithmeticException)
return SupervisorStrategy.resume();
if (param instanceof
NullPointerException)
return SupervisorStrategy.stop();
else return SupervisorStrategy.escalate();
}
}
);
}
示例2: apply
import akka.actor.SupervisorStrategy; //导入方法依赖的package包/类
@Override
public Directive apply(Throwable t) {
logger.error(t, "Unknown failure");
if (t instanceof RuntimeException) {
return SupervisorStrategy.restart();
} else {
return SupervisorStrategy.stop();
}
}
示例3: supervisorStrategy
import akka.actor.SupervisorStrategy; //导入方法依赖的package包/类
@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();
}
}
);
}
示例4: myDecider
import akka.actor.SupervisorStrategy; //导入方法依赖的package包/类
private Function<Throwable, Directive> myDecider()
{
return new Function<Throwable, Directive>()
{
@Override
public Directive apply(Throwable t)
{
if ( t instanceof ActorInitializationException
|| t instanceof ActorKilledException
|| t instanceof DeathPactException )
{
return SupervisorStrategy.stop();
}
else if ( t instanceof Exception )
{
Class<? extends Throwable> clazz = t.getClass();
ImmutableSet<Entry<Class<?>, Method>> entrySet = javactorInfoByJavactorType
.get(javactor.getClass()).getSupervisorStrategyInfo().getOnExceptionMethods()
.entrySet();
for (Entry<Class<?>, Method> entry : entrySet)
{
if (entry.getKey().isAssignableFrom(clazz))
{
final Method method = entry.getValue();
try
{
return map((SupervisorDirective) methodInvoke(
method, javactor, t));
} catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
return SupervisorStrategy.restart();
} else {
return SupervisorStrategy.escalate();
}
}
};
}
示例5: defaultStrategy
import akka.actor.SupervisorStrategy; //导入方法依赖的package包/类
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();
}