第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何檢測akka actor終止是由于系統(tǒng)關(guān)閉并避免重新啟動(dòng)它

如何檢測akka actor終止是由于系統(tǒng)關(guān)閉并避免重新啟動(dòng)它

holdtom 2023-06-04 17:41:48
我有一個(gè) Spring 應(yīng)用程序,它使用一個(gè)小型 Akka actor 系統(tǒng)(使用 Java),其中我有一個(gè)MasterActor擴(kuò)展 Akka 的系統(tǒng)AbstractActor,它初始化 aRouter并設(shè)置一些 worker actor。它還監(jiān)視工人的生命周期。我想重啟一個(gè) Worker 演員,如果它恰好因?yàn)槟承┰蚨劳鯡xception。 public MasterActor(ActorPropsFactory actorPropsFactory) {    this.actorPropsFactory = actorPropsFactory;    int workers = Runtime.getRuntime().availableProcessors() - 1;    List<Routee> routees = Stream.generate(this::createActorRefRoutee).limit(workers).collect(Collectors.toList());    this.router = new Router(new ConsistentHashingRoutingLogic(getContext().system()), routees);  }  private ActorRefRoutee createActorRefRoutee() {    ActorRef worker = getContext().actorOf(actorPropsFactory.create(getWorkerActorClass()));    getContext().watch(worker);    return new ActorRefRoutee(worker);  }  private void route(Object message, Supplier<String> routingKeySupplier) {    String routingKey = routingKeySupplier.get();    RouterEnvelope envelope = new ConsistentHashingRouter.ConsistentHashableEnvelope(message, routingKey);    router.route(envelope, getSender());  } @Override  public Receive createReceive() {    return receiveBuilder()        .match(            EventMessage.class,            message -> this.route(message, () -> message.getEvent().getId().toString()))        .match(            Terminated.class,            message -> {              logger.info("WorkerActor {} terminated, restarting", message.getActor());              // todo: detect whether the system is shutting down before restarting the actor              router = router.removeRoutee(message.actor())                             .addRoutee(createActorRefRoutee());            })        .build();  }我遇到的問題是,如果 Spring 應(yīng)用程序無法啟動(dòng)。(例如,它無法連接到數(shù)據(jù)庫,或者某些憑據(jù)不正確等等),我收到了Terminated所有工作人員的消息,Master actor 嘗試啟動(dòng)新的,這也會(huì)Terminated立即進(jìn)入,進(jìn)入無限循環(huán)。檢測這種情況的正確方法是什么?有沒有辦法讓 Master actor 檢測到 actor 系統(tǒng)正在關(guān)閉,這樣 workers 就不會(huì)再次重啟?
查看完整描述

1 回答

?
守著星空守著你

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊

難道你不能只為你的路由器設(shè)置一個(gè)監(jiān)督策略,這樣你就可以檢查導(dǎo)致失敗的異常類型嗎?這樣你也不需要手動(dòng)重啟你的工人。


編輯:


SupervisorStrategy你這樣設(shè)置:


private static SupervisorStrategy strategy=

    new OneForOneStrategy(

    10,

    Duration.ofMinutes(1),

    DeciderBuilder.match(ArithmeticException.class,e->SupervisorStrategy.resume())

    .match(NullPointerException.class,e->SupervisorStrategy.restart())

    .match(IllegalArgumentException.class,e->SupervisorStrategy.stop())

    .matchAny(o->SupervisorStrategy.escalate())

    .build());

final ActorRef router=

        system.actorOf(

        new RoundRobinPool(5).withSupervisorStrategy(strategy).props(Props.create(Echo.class)));


查看完整回答
反對 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 171 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號