Skip to content

Commit

Permalink
Minor review findings
Browse files Browse the repository at this point in the history
* Fix restarting of enforcer actor child
* Fix spelling

Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
  • Loading branch information
Yannic92 committed May 13, 2022
1 parent 9c273f4 commit b10782f
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected boolean isStartChildImmediately() {
protected Receive activeBehaviour() {
return ReceiveBuilder.create()
.match(Terminated.class, this::childTerminated)
.matchEquals(Control.START_CHILDS, this::startChilds)
.matchEquals(Control.START_CHILDREN, this::startChildren)
.matchEquals(Control.PASSIVATE, this::passivate)
.match(SudoCommand.class, this::forwardSudoCommandToChildIfAvailable)
.match(WithDittoHeaders.class, w -> w.getDittoHeaders().isSudo(),
Expand Down Expand Up @@ -234,7 +234,7 @@ public Receive createReceive() {
return ReceiveBuilder.create()
.matchEquals(Control.INIT_DONE, initDone -> {
entityId = getEntityId();
startChilds(Control.START_CHILDS);
startChildren(Control.START_CHILDREN);
unstashAll();
becomeActive(getShutdownBehaviour(entityId));
})
Expand Down Expand Up @@ -266,7 +266,12 @@ private void passivate(final Control passivationTrigger) {
getContext().getParent().tell(new ShardRegion.Passivate(PoisonPill.getInstance()), getSelf());
}

private void startChilds(final Control startChild) {
private void startChildren(final Control startChild) {
ensurePersistenceActorBeeingStarted();
ensureEnforcerActorBeeingStarted();
}

private void ensurePersistenceActorBeeingStarted() {
if (null == persistenceActorChild) {
log.debug("Starting persistence actor for entity with ID <{}>.", entityId);
assert entityId != null;
Expand All @@ -275,11 +280,9 @@ private void startChilds(final Control startChild) {
} else {
log.debug("Not starting persistence child actor because it is started already.");
}

startEnforcerActor();
}

private void startEnforcerActor() {
private void ensureEnforcerActorBeeingStarted() {
if (null == enforcerChild) {
log.debug("Starting enforcer actor for entity with ID <{}>.", entityId);
assert entityId != null;
Expand All @@ -299,26 +302,26 @@ protected void restartChild() {

private void childTerminated(final Terminated message) {
if (message.getActor().equals(persistenceActorChild)) {
persistenceActorChild = null;
if (waitingForStopBeforeRestart) {
log.info("Persistence actor for entity with ID <{}> was stopped and will now be started again.",
entityId);
persistenceActorChild = null;
self().tell(Control.START_CHILDS, ActorRef.noSender());
self().tell(Control.START_CHILDREN, ActorRef.noSender());
} else {
if (message.getAddressTerminated()) {
log.error("Persistence actor for entity with ID <{}> terminated abnormally " +
"because it crashed or because of network failure!", entityId);
} else {
log.warning("Persistence actor for entity with ID <{}> terminated abnormally.", entityId);
}
persistenceActorChild = null;
backOff = backOff.calculateNextBackOff();
final Duration restartDelay = backOff.getRestartDelay();
getTimers().startSingleTimer(Control.START_CHILDS, Control.START_CHILDS, restartDelay);
getTimers().startSingleTimer(Control.START_CHILDREN, Control.START_CHILDREN, restartDelay);
}
} else if (message.getActor().equals(enforcerChild)) {
enforcerChild = null;
// simply restart the enforcer actor
startEnforcerActor();
ensureEnforcerActorBeeingStarted();
}
}

Expand Down Expand Up @@ -543,9 +546,9 @@ public enum Control {
PASSIVATE,

/**
* Request to start child actor.
* Request to start child actors.
*/
START_CHILDS,
START_CHILDREN,

/**
* Signals initialization is done, child actors can be started.
Expand Down

0 comments on commit b10782f

Please sign in to comment.