return new ConnectionSupervisorActor(new OneForOneStrategy(true, DeciderBuilder .match(JMSRuntimeException.class, e -> SupervisorStrategy.resume()) .match(NullPointerException.class, e -> SupervisorStrategy.restart())
private void startChild() { LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); if (child == null) { log.debug("Starting persistence actor for Connection with ID '{}'", connectionId); final ActorRef childRef = getContext().actorOf(persistenceActorProps, "pa"); child = getContext().watch(childRef); } }
private ConnectionSupervisorActor(final SupervisorStrategy supervisorStrategy, final Duration minBackoff, final Duration maxBackoff, final double randomFactor, final ActorRef pubSubMediator, final ActorRef conciergeForwarder, final ClientActorPropsFactory propsFactory, @Nullable final ConnectivityCommandInterceptor commandValidator) { try { this.connectionId = URLDecoder.decode(getSelf().path().name(), StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new IllegalStateException("Unsupported encoding", e); } this.supervisorStrategy = supervisorStrategy; this.minBackoff = minBackoff; this.maxBackoff = maxBackoff; this.randomFactor = randomFactor; this.persistenceActorProps = ConnectionActor.props(connectionId, pubSubMediator, conciergeForwarder, propsFactory, commandValidator); }
@Override public Receive createReceive() { return ReceiveBuilder.create() .match(StartChild.class, startChild -> startChild()) .match(ManualReset.class, manualReset -> restartCount = 0) .match(Terminated.class, terminated -> { log.info("Persistence actor for Connection with ID '{}' terminated abnormally", connectionId); child = null; final Duration restartDelay = calculateRestartDelay(); getContext().system().scheduler() .scheduleOnce(new FiniteDuration(restartDelay.toNanos(), TimeUnit.NANOSECONDS), getSelf(), StartChild.getInstance(), getContext().dispatcher(), null); restartCount += 1; }) LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); if (child != null) { if (child.equals(getSender())) { log.warning("Received unhandled message from child actor '{}': {}", connectionId, message); unhandled(message); } else { log.debug("Forwarding <{}> message to child {}.", message.getClass().getSimpleName(), child.path()); child.forward(message, getContext()); getSender().tell(builder.build(), getSelf());
@Override public void preStart() throws Exception { super.preStart(); startChild(); }
ConnectionSupervisorActor.props(minBackoff, maxBackoff, randomFactor, pubSubMediator, conciergeForwarder, propsFactory, commandValidator);
@Override public Receive createReceive() { return ReceiveBuilder.create() .match(StartChild.class, startChild -> startChild()) .match(ManualReset.class, manualReset -> restartCount = 0) .match(Terminated.class, terminated -> { log.info("Persistence actor for Connection with ID '{}' terminated abnormally", connectionId); child = null; final Duration restartDelay = calculateRestartDelay(); getContext().system().scheduler() .scheduleOnce(new FiniteDuration(restartDelay.toNanos(), TimeUnit.NANOSECONDS), getSelf(), StartChild.getInstance(), getContext().dispatcher(), null); restartCount += 1; }) LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); if (child != null) { if (child.equals(getSender())) { log.warning("Received unhandled message from child actor '{}': {}", connectionId, message); unhandled(message); } else { log.debug("Forwarding <{}> message to child {}.", message.getClass().getSimpleName(), child.path()); child.forward(message, getContext()); getSender().tell(builder.build(), getSelf());
@Override public void preStart() throws Exception { super.preStart(); startChild(); }
return new ConnectionSupervisorActor(new OneForOneStrategy(true, DeciderBuilder .match(JMSRuntimeException.class, e -> SupervisorStrategy.resume()) .match(NullPointerException.class, e -> SupervisorStrategy.restart())
private void startChild() { LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); if (child == null) { log.debug("Starting persistence actor for Connection with ID '{}'", connectionId); final ActorRef childRef = getContext().actorOf(persistenceActorProps, "pa"); child = getContext().watch(childRef); } }
private ConnectionSupervisorActor(final SupervisorStrategy supervisorStrategy, final Duration minBackoff, final Duration maxBackoff, final double randomFactor, final ActorRef pubSubMediator, final ActorRef conciergeForwarder, final ClientActorPropsFactory propsFactory, @Nullable final ConnectivityCommandInterceptor commandValidator) { try { this.connectionId = URLDecoder.decode(getSelf().path().name(), StandardCharsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new IllegalStateException("Unsupported encoding", e); } this.supervisorStrategy = supervisorStrategy; this.minBackoff = minBackoff; this.maxBackoff = maxBackoff; this.randomFactor = randomFactor; this.persistenceActorProps = ConnectionActor.props(connectionId, pubSubMediator, conciergeForwarder, propsFactory, commandValidator); }
@Override public ConnectionSupervisorActor create() { return new ConnectionSupervisorActor(new OneForOneStrategy(true, DeciderBuilder .match(JMSRuntimeException.class, e -> SupervisorStrategy.resume()) .match(NullPointerException.class, e -> SupervisorStrategy.restart()) .match(JMSException.class, e -> SupervisorStrategy.stop()) .match(NamingException.class, e -> SupervisorStrategy.stop()) .match(ActorKilledException.class, e -> SupervisorStrategy.stop()) .matchAny(e -> SupervisorStrategy.escalate()) .build()), minBackoff, maxBackoff, randomFactor, pubSubMediator, conciergeForwarder, propsFactory, commandValidator); } });
@Override public ConnectionSupervisorActor create() { return new ConnectionSupervisorActor(new OneForOneStrategy(true, DeciderBuilder .match(JMSRuntimeException.class, e -> SupervisorStrategy.resume()) .match(NullPointerException.class, e -> SupervisorStrategy.restart()) .match(JMSException.class, e -> SupervisorStrategy.stop()) .match(NamingException.class, e -> SupervisorStrategy.stop()) .match(ActorKilledException.class, e -> SupervisorStrategy.stop()) .matchAny(e -> SupervisorStrategy.escalate()) .build()), minBackoff, maxBackoff, randomFactor, pubSubMediator, conciergeForwarder, propsFactory, commandValidator); } });