From a8080a214040c060cff1e62c016ae19b20feb45c Mon Sep 17 00:00:00 2001 From: Nicolas Vollmar Date: Fri, 21 Dec 2018 19:06:30 +0100 Subject: [PATCH] Improving documentation and code style #26156 --- .../akka/pattern/BackoffOnStopSupervisor.scala | 9 +++------ .../main/scala/akka/pattern/BackoffOptions.scala | 5 +++-- .../main/scala/akka/pattern/BackoffSupervisor.scala | 2 +- .../src/main/scala/akka/pattern/HandleBackoff.scala | 13 +++++++------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/akka-actor/src/main/scala/akka/pattern/BackoffOnStopSupervisor.scala b/akka-actor/src/main/scala/akka/pattern/BackoffOnStopSupervisor.scala index a2526fb8d4..89073e6f6f 100644 --- a/akka-actor/src/main/scala/akka/pattern/BackoffOnStopSupervisor.scala +++ b/akka-actor/src/main/scala/akka/pattern/BackoffOnStopSupervisor.scala @@ -78,15 +78,12 @@ private[akka] class BackoffOnStopSupervisor( } case None ⇒ replyWhileStopped match { - case None ⇒ context.system.deadLetters.forward(msg) case Some(r) ⇒ sender() ! r + case None ⇒ context.system.deadLetters.forward(msg) } finalStopMessage match { - case None ⇒ - case Some(fsm) ⇒ - if (fsm(msg)) { - context.stop(self) - } + case Some(fsm) if fsm(msg) ⇒ context.stop(self) + case _ ⇒ } } } diff --git a/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala b/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala index a629b4eaa7..5b90e6ae63 100644 --- a/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala +++ b/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala @@ -552,8 +552,9 @@ trait BackoffOptions { * Returns a new BackoffOptions with a maximum number of retries to restart the child actor. * By default, the supervisor will retry infinitely. * With this option, the supervisor will terminate itself after the maxNoOfRetries is reached. - * @param maxNrOfRetries the number of times a child actor is allowed to be restarted, negative value means no limit, - * if the limit is exceeded the child actor is stopped + * @param maxNrOfRetries the number of times a child actor is allowed to be restarted. + * If negative, the value is unbounded, otherwise the provided + * limit is used. If the limit is exceeded the child actor will be stopped. */ def withMaxNrOfRetries(maxNrOfRetries: Int): BackoffOptions diff --git a/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala b/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala index b88f012f39..0aa462a91a 100644 --- a/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala +++ b/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala @@ -278,7 +278,7 @@ object BackoffSupervisor { } // for backwards compability -@deprecated("Use BackoffSupervisor props method instead", since = "2.5.20") +@deprecated("Use `BackoffSupervisor.props` method instead", since = "2.5.20") final class BackoffSupervisor( override val childProps: Props, override val childName: String, diff --git a/akka-actor/src/main/scala/akka/pattern/HandleBackoff.scala b/akka-actor/src/main/scala/akka/pattern/HandleBackoff.scala index 7920967656..4798ec75a5 100644 --- a/akka-actor/src/main/scala/akka/pattern/HandleBackoff.scala +++ b/akka-actor/src/main/scala/akka/pattern/HandleBackoff.scala @@ -6,6 +6,9 @@ package akka.pattern import akka.actor.{ Actor, ActorRef, Props } +/** + * Implements basic backoff handling for [[BackoffOnRestartSupervisor]] and [[BackoffOnStopSupervisor]]. + */ private[akka] trait HandleBackoff { this: Actor ⇒ def childProps: Props @@ -22,18 +25,16 @@ private[akka] trait HandleBackoff { override def preStart(): Unit = startChild() - def startChild(): Unit = { - if (child.isEmpty) { - child = Some(context.watch(context.actorOf(childProps, childName))) - } + def startChild(): Unit = if (child.isEmpty) { + child = Some(context.watch(context.actorOf(childProps, childName))) } - def handleBackoff: Receive = { + def handleBackoff: Actor.Receive = { case StartChild ⇒ startChild() reset match { case AutoReset(resetBackoff) ⇒ - val _ = context.system.scheduler.scheduleOnce(resetBackoff, self, ResetRestartCount(restartCount)) + context.system.scheduler.scheduleOnce(resetBackoff, self, ResetRestartCount(restartCount)) case _ ⇒ // ignore }