diff --git a/akka-actor/src/main/scala/akka/pattern/Backoff.scala b/akka-actor/src/main/scala/akka/pattern/Backoff.scala index bfcbe61a61..938995518c 100644 --- a/akka-actor/src/main/scala/akka/pattern/Backoff.scala +++ b/akka-actor/src/main/scala/akka/pattern/Backoff.scala @@ -11,10 +11,10 @@ import akka.util.JavaDurationConverters._ import scala.concurrent.duration.{ Duration, FiniteDuration } /** - * @deprecated This API is superseded by the [[BackoffOptions]] object. + * @deprecated This API is superseded by the [[BackoffOpts]] object. */ @Deprecated -@deprecated("Use new API from BackoffOptions object instead", since = "2.5.20") +@deprecated("Use new API from BackoffOpts object instead", since = "2.5.22") object Backoff { /** * Back-off options for creating a back-off supervisor actor that expects a child actor to restart on failure. @@ -66,7 +66,7 @@ object Backoff { * In order to restart infinitely pass in `-1`. * */ - @deprecated("Use BackoffOptions.onFailure instead", "2.5.20") + @deprecated("Use BackoffOpts.onFailure instead", "2.5.22") def onFailure( childProps: Props, childName: String, @@ -122,7 +122,7 @@ object Backoff { * random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. * In order to skip this additional delay pass in `0`. */ - @deprecated("Use BackoffOptions.onFailure instead", "2.5.20") + @deprecated("Use BackoffOpts.onFailure instead", "2.5.22") def onFailure( childProps: Props, childName: String, @@ -181,7 +181,7 @@ object Backoff { * In order to restart infinitely pass in `-1`. */ @Deprecated - @deprecated("Use BackoffOptions.onFailure instead", "2.5.20") + @deprecated("Use BackoffOpts.onFailure instead", "2.5.22") def onFailure( childProps: Props, childName: String, @@ -303,7 +303,7 @@ object Backoff { * The supervisor will terminate itself after the maxNoOfRetries is reached. * In order to restart infinitely pass in `-1`. */ - @deprecated("Use BackoffOptions.onStop instead", "2.5.20") + @deprecated("Use BackoffOpts.onStop instead", "2.5.22") def onStop( childProps: Props, childName: String, @@ -366,7 +366,7 @@ object Backoff { * random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. * In order to skip this additional delay pass in `0`. */ - @deprecated("Use BackoffOptions.onStop instead", "2.5.20") + @deprecated("Use BackoffOpts.onStop instead", "2.5.22") def onStop( childProps: Props, childName: String, @@ -432,7 +432,7 @@ object Backoff { * In order to restart infinitely pass in `-1`. */ @Deprecated - @deprecated("Use BackoffOptions.onStop instead", "2.5.20") + @deprecated("Use BackoffOpts.onStop instead", "2.5.22") def onStop( childProps: Props, childName: String, @@ -517,7 +517,7 @@ object Backoff { */ @DoNotInherit @Deprecated -@deprecated("Use new API from BackoffOptions object instead", since = "2.5.22") +@deprecated("Use new API from BackoffOpts object instead", since = "2.5.22") trait BackoffOptions { /** diff --git a/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala b/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala index d63d1826f6..03f79517eb 100644 --- a/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala +++ b/akka-actor/src/main/scala/akka/pattern/BackoffOptions.scala @@ -245,6 +245,9 @@ object BackoffOpts { onStop(childProps, childName, minBackoff.asScala, maxBackoff.asScala, randomFactor) } +/** + * Not for user extension + */ @DoNotInherit private[akka] sealed trait ExtendedBackoffOptions[T <: ExtendedBackoffOptions[T]] { diff --git a/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala b/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala index 8afb50f4f6..08ccaafc00 100644 --- a/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala +++ b/akka-actor/src/main/scala/akka/pattern/BackoffSupervisor.scala @@ -32,7 +32,7 @@ object BackoffSupervisor { * random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. * In order to skip this additional delay pass in `0`. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def props( childProps: Props, childName: String, @@ -62,7 +62,7 @@ object BackoffSupervisor { * The supervisor will terminate itself after the maxNoOfRetries is reached. * In order to restart infinitely pass in `-1`. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def props( childProps: Props, childName: String, @@ -94,7 +94,7 @@ object BackoffSupervisor { * random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. * In order to skip this additional delay pass in `0`. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def props( childProps: Props, childName: String, @@ -124,7 +124,7 @@ object BackoffSupervisor { * The supervisor will terminate itself after the maxNoOfRetries is reached. * In order to restart infinitely pass in `-1`. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def props( childProps: Props, childName: String, @@ -156,7 +156,7 @@ object BackoffSupervisor { * in the child. As the BackoffSupervisor creates a separate actor to handle the * backoff process, only a [[OneForOneStrategy]] makes sense here. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def propsWithSupervisorStrategy( childProps: Props, childName: String, @@ -191,7 +191,7 @@ object BackoffSupervisor { * in the child. As the BackoffSupervisor creates a separate actor to handle the * backoff process, only a [[OneForOneStrategy]] makes sense here. */ - @deprecated("Use props with BackoffOptions instead", since = "2.5.20") + @deprecated("Use props with BackoffOpts instead", since = "2.5.22") def propsWithSupervisorStrategy( childProps: Props, childName: String, @@ -207,7 +207,7 @@ object BackoffSupervisor { * * @param options the [[BackoffOptions]] that specify how to construct a backoff-supervisor. */ - @deprecated("Use new API from BackoffOptions object instead", since = "2.5.20") + @deprecated("Use new API from BackoffOpts object instead", since = "2.5.22") def props(options: BackoffOptions): Props = options.props /** @@ -299,7 +299,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.22") final class BackoffSupervisor( override val childProps: Props, override val childName: String, diff --git a/akka-docs/src/main/paradox/general/supervision.md b/akka-docs/src/main/paradox/general/supervision.md index 89cecb9325..58d102e632 100644 --- a/akka-docs/src/main/paradox/general/supervision.md +++ b/akka-docs/src/main/paradox/general/supervision.md @@ -207,6 +207,7 @@ to recover before the persistent actor is started. > [1] A failure can be indicated in two different ways; by an actor stopping or crashing. + #### Supervision strategies There are two basic supervision strategies available for backoff: diff --git a/akka-docs/src/main/paradox/persistence.md b/akka-docs/src/main/paradox/persistence.md index 2aafd25a10..6f15c4505b 100644 --- a/akka-docs/src/main/paradox/persistence.md +++ b/akka-docs/src/main/paradox/persistence.md @@ -466,6 +466,8 @@ Scala Java : @@snip [LambdaPersistenceDocTest.java](/akka-docs/src/test/java/jdocs/persistence/LambdaPersistenceDocTest.java) { #backoff } +See @ref:[Supervision strategies](general/supervision.md#supervision-strategies) for more details about actor supervision. + If persistence of an event is rejected before it is stored, e.g. due to serialization error, `onPersistRejected` will be invoked (logging a warning by default), and the actor continues with next message. diff --git a/akka-docs/src/test/java/jdocs/persistence/LambdaPersistenceDocTest.java b/akka-docs/src/test/java/jdocs/persistence/LambdaPersistenceDocTest.java index a2f01bf42e..7307148caf 100644 --- a/akka-docs/src/test/java/jdocs/persistence/LambdaPersistenceDocTest.java +++ b/akka-docs/src/test/java/jdocs/persistence/LambdaPersistenceDocTest.java @@ -6,11 +6,12 @@ package jdocs.persistence; import akka.actor.*; import akka.japi.Procedure; +import akka.pattern.BackoffOpts; import akka.pattern.BackoffSupervisor; import akka.persistence.*; -import java.time.Duration; import java.io.Serializable; +import java.time.Duration; import java.util.Optional; public class LambdaPersistenceDocTest { @@ -20,6 +21,7 @@ public class LambdaPersistenceDocTest { public interface PersistentActorMethods { // #persistence-id public String persistenceId(); + // #persistence-id // #recovery-status public boolean recoveryRunning(); @@ -136,7 +138,8 @@ public class LambdaPersistenceDocTest { final Props childProps = Props.create(MyPersistentActor1.class); final Props props = BackoffSupervisor.props( - childProps, "myActor", Duration.ofSeconds(3), Duration.ofSeconds(30), 0.2); + BackoffOpts.onStop( + childProps, "myActor", Duration.ofSeconds(3), Duration.ofSeconds(30), 0.2)); getContext().actorOf(props, "mySupervisor"); super.preStart(); } diff --git a/akka-docs/src/test/scala/docs/persistence/PersistenceDocSpec.scala b/akka-docs/src/test/scala/docs/persistence/PersistenceDocSpec.scala index d2341d89e9..5fe99ebdd9 100644 --- a/akka-docs/src/test/scala/docs/persistence/PersistenceDocSpec.scala +++ b/akka-docs/src/test/scala/docs/persistence/PersistenceDocSpec.scala @@ -5,10 +5,10 @@ package docs.persistence import akka.actor._ -import akka.pattern.{ Backoff, BackoffSupervisor } +import akka.pattern.{ Backoff, BackoffOpts, BackoffSupervisor } import akka.persistence._ import akka.stream.ActorMaterializer -import akka.stream.scaladsl.{ Source, Sink, Flow } +import akka.stream.scaladsl.{ Flow, Sink, Source } import scala.concurrent.duration._ import scala.language.postfixOps @@ -96,15 +96,14 @@ object PersistenceDocSpec { abstract class MyActor extends Actor { import PersistAsync.MyPersistentActor //#backoff - val childProps = Props[MyPersistentActor] + val childProps = Props[MyPersistentActor]() val props = BackoffSupervisor.props( - Backoff.onStop( + BackoffOpts.onStop( childProps, childName = "myActor", minBackoff = 3.seconds, maxBackoff = 30.seconds, - randomFactor = 0.2, - maxNrOfRetries = -1)) + randomFactor = 0.2)) context.actorOf(props, name = "mySupervisor") //#backoff }