diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorCompile.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorCompile.java index 4af5520eb5..098165ec2b 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorCompile.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorCompile.java @@ -38,7 +38,7 @@ public class ActorCompile { Behavior actor5 = ignore(); Behavior actor6 = tap((ctx, signal) -> {}, (ctx, msg) -> {}, actor5); Behavior actor7 = actor6.narrow(); - Behavior actor8 = deferred(ctx -> { + Behavior actor8 = setup(ctx -> { final ActorRef self = ctx.getSelf(); return monitor(self, ignore()); }); diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorContextAskTest.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorContextAskTest.java index 0f101b881c..99ea9cc784 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorContextAskTest.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ActorContextAskTest.java @@ -44,7 +44,7 @@ public class ActorContextAskTest extends JUnitSuite { final TestProbe probe = new TestProbe<>(Adapter.toTyped(system)); - final Behavior snitch = Behaviors.deferred((ActorContext ctx) -> { + final Behavior snitch = Behaviors.setup((ActorContext ctx) -> { ctx.ask(Pong.class, pingPong, new Timeout(3, TimeUnit.SECONDS), diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/FaultToleranceDocTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/FaultToleranceDocTest.java index 20367f85c0..0ad905ece2 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/FaultToleranceDocTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/FaultToleranceDocTest.java @@ -31,7 +31,7 @@ public class FaultToleranceDocTest extends JUnitSuite { }) .build(); - Behavior middleManagementBehavior = Behaviors.deferred((ctx) -> { + Behavior middleManagementBehavior = Behaviors.setup((ctx) -> { ctx.getLog().info("Middle management starting up"); final ActorRef child = ctx.spawn(failingChildBehavior, "child"); // we want to know when the child terminates, but since we do not handle @@ -49,7 +49,7 @@ public class FaultToleranceDocTest extends JUnitSuite { }).build(); }); - Behavior bossBehavior = Behaviors.deferred((ctx) -> { + Behavior bossBehavior = Behaviors.setup((ctx) -> { ctx.getLog().info("Boss starting up"); final ActorRef middleManagement = ctx.spawn(middleManagementBehavior, "middle-management"); ctx.watch(middleManagement); diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/InteractionPatternsTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/InteractionPatternsTest.java index b089e097d4..cfd9424157 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/InteractionPatternsTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/InteractionPatternsTest.java @@ -3,7 +3,6 @@ */ package jdocs.akka.typed; -import akka.NotUsed; import akka.actor.typed.ActorRef; import akka.actor.typed.ActorSystem; import akka.actor.typed.Behavior; @@ -376,7 +375,7 @@ public class InteractionPatternsTest extends JUnitSuite { } public static Behavior daveBehavior(final ActorRef hal) { - return Behaviors.deferred((ActorContext ctx) -> { + return Behaviors.setup((ActorContext ctx) -> { // asking someone requires a timeout, if the timeout hits without response // the ask is failed with a TimeoutException @@ -507,7 +506,7 @@ public class InteractionPatternsTest extends JUnitSuite { // actor behavior public Behavior homeBehavior() { - return Behaviors.deferred((ctx) -> { + return Behaviors.setup((ctx) -> { final ActorRef keyCabinet = ctx.spawn(keyCabinetBehavior, "key-cabinet"); final ActorRef drawer = ctx.spawn(drawerBehavior, "drawer"); diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java index efcf9b0e5d..27c1d2bd04 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java @@ -212,7 +212,7 @@ public class IntroTest { public static void runChatRoom() throws Exception { //#chatroom-main - Behavior main = Behaviors.deferred(ctx -> { + Behavior main = Behaviors.setup(ctx -> { ActorRef chatRoom = ctx.spawn(ChatRoom.behavior(), "chatRoom"); ActorRef gabbler = diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StashDocTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StashDocTest.java index 59cba6e870..d870a4214d 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StashDocTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/StashDocTest.java @@ -88,7 +88,7 @@ public class StashDocTest extends JUnitSuite { } Behavior behavior() { - return Behaviors.deferred(ctx -> { + return Behaviors.setup(ctx -> { db.load(id) .whenComplete((value, cause) -> { if (cause == null) diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/TypedWatchingUntypedTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/TypedWatchingUntypedTest.java index 67588f2d59..a20f6cec2c 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/TypedWatchingUntypedTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/TypedWatchingUntypedTest.java @@ -36,7 +36,7 @@ public class TypedWatchingUntypedTest extends JUnitSuite { public static class Pong implements Command { } public static Behavior behavior() { - return akka.actor.typed.javadsl.Behaviors.deferred(context -> { + return akka.actor.typed.javadsl.Behaviors.setup(context -> { akka.actor.ActorRef second = Adapter.actorOf(context, Untyped.props(), "second"); Adapter.watch(context, second); diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/ActorContextSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/ActorContextSpec.scala index 7ba560cd4d..b722d13763 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/ActorContextSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/ActorContextSpec.scala @@ -848,13 +848,13 @@ class WidenedActorContextSpec extends ActorContextSpec { class DeferredActorContextSpec extends ActorContextSpec { override def suite = "deferred" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = - Behaviors.deferred(_ ⇒ subject(ctx.self, ignorePostStop)) + Behaviors.setup(_ ⇒ subject(ctx.self, ignorePostStop)) } class NestedDeferredActorContextSpec extends ActorContextSpec { override def suite = "nexted-deferred" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = - Behaviors.deferred(_ ⇒ Behaviors.deferred(_ ⇒ subject(ctx.self, ignorePostStop))) + Behaviors.setup(_ ⇒ Behaviors.setup(_ ⇒ subject(ctx.self, ignorePostStop))) } class TapActorContextSpec extends ActorContextSpec { diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/BehaviorSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/BehaviorSpec.scala index fc33eff3a6..a92678c7e3 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/BehaviorSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/BehaviorSpec.scala @@ -494,7 +494,7 @@ class DeferredScalaBehaviorSpec extends ImmutableWithSignalScalaBehaviorSpec { override def behavior(monitor: ActorRef[Event]): (Behavior[Command], Aux) = { val inbox = TestInbox[Done]("deferredListener") - (SActor.deferred(_ ⇒ { + (SActor.setup(_ ⇒ { inbox.ref ! Done super.behavior(monitor)._1 }), inbox) @@ -594,7 +594,7 @@ class DeferredJavaBehaviorSpec extends ImmutableWithSignalJavaBehaviorSpec { override def behavior(monitor: ActorRef[Event]): (Behavior[Command], Aux) = { val inbox = TestInbox[Done]("deferredListener") - (JActor.deferred(df(_ ⇒ { + (JActor.setup(df(_ ⇒ { inbox.ref ! Done super.behavior(monitor)._1 })), inbox) diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/DeferredSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/DeferredSpec.scala index 00e495b117..6656a24420 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/DeferredSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/DeferredSpec.scala @@ -34,7 +34,7 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "Deferred behavior" must { "must create underlying" in { val probe = TestProbe[Event]("evt") - val behv = Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { _ ⇒ probe.ref ! Started target(probe.ref) } @@ -46,8 +46,8 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must stop when exception from factory" in { val probe = TestProbe[Event]("evt") - val behv = Behaviors.deferred[Command] { ctx ⇒ - val child = ctx.spawnAnonymous(Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { ctx ⇒ + val child = ctx.spawnAnonymous(Behaviors.setup[Command] { _ ⇒ probe.ref ! Started throw new RuntimeException("simulated exc from factory") with NoStackTrace }) @@ -65,8 +65,8 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must stop when deferred result it Stopped" in { val probe = TestProbe[Event]("evt") - val behv = Behaviors.deferred[Command] { ctx ⇒ - val child = ctx.spawnAnonymous(Behaviors.deferred[Command](_ ⇒ Behaviors.stopped)) + val behv = Behaviors.setup[Command] { ctx ⇒ + val child = ctx.spawnAnonymous(Behaviors.setup[Command](_ ⇒ Behaviors.stopped)) ctx.watch(child) Behaviors.immutable[Command]((_, _) ⇒ Behaviors.same).onSignal { case (_, Terminated(`child`)) ⇒ @@ -80,8 +80,8 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must create underlying when nested" in { val probe = TestProbe[Event]("evt") - val behv = Behaviors.deferred[Command] { _ ⇒ - Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { _ ⇒ + Behaviors.setup[Command] { _ ⇒ probe.ref ! Started target(probe.ref) } @@ -92,7 +92,7 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must un-defer underlying when wrapped by widen" in { val probe = TestProbe[Event]("evt") - val behv = Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { _ ⇒ probe.ref ! Started target(probe.ref) }.widen[Command] { @@ -110,7 +110,7 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { // monitor is implemented with tap, so this is testing both val probe = TestProbe[Event]("evt") val monitorProbe = TestProbe[Command]("monitor") - val behv = Behaviors.monitor(monitorProbe.ref, Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.monitor(monitorProbe.ref, Behaviors.setup[Command] { _ ⇒ probe.ref ! Started target(probe.ref) }) @@ -131,7 +131,7 @@ class DeferredStubbedSpec extends TypedAkkaSpec { "must create underlying deferred behavior immediately" in { val inbox = TestInbox[Event]("evt") - val behv = Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { _ ⇒ inbox.ref ! Started target(inbox.ref) } @@ -143,7 +143,7 @@ class DeferredStubbedSpec extends TypedAkkaSpec { "must stop when exception from factory" in { val inbox = TestInbox[Event]("evt") val exc = new RuntimeException("simulated exc from factory") with NoStackTrace - val behv = Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.setup[Command] { _ ⇒ inbox.ref ! Started throw exc } diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/StepWise.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/StepWise.scala index 8fdea9ea19..669dcaaefb 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/StepWise.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/StepWise.scala @@ -109,7 +109,7 @@ object StepWise { } def apply[T](f: (scaladsl.ActorContext[T], StartWith[T]) ⇒ Steps[T, _]): Behavior[T] = - deferred[Any] { ctx ⇒ + setup[Any] { ctx ⇒ run(ctx, f(ctx.asInstanceOf[scaladsl.ActorContext[T]], new StartWith(keepTraces = false)).ops.reverse, ()) }.narrow diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SupervisionSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SupervisionSpec.scala index 5f15928af8..0a142f082d 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SupervisionSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SupervisionSpec.scala @@ -229,7 +229,7 @@ class StubbedSupervisionSpec extends WordSpec with Matchers { "create underlying deferred behavior immediately" in { val inbox = TestInbox[Event]("evt") - val behv = supervise(deferred[Command] { _ ⇒ + val behv = supervise(setup[Command] { _ ⇒ inbox.ref ! Started targetBehavior(inbox.ref) }).onFailure[Exc1](SupervisorStrategy.restart) @@ -270,7 +270,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec", ConfigFactory.parseStri class FailingDeferredTestSetup(failCount: Int, strategy: SupervisorStrategy) { val probe = TestProbe[AnyRef]("evt") val failCounter = new AtomicInteger(0) - def behv = supervise(deferred[Command] { _ ⇒ + def behv = supervise(setup[Command] { _ ⇒ val count = failCounter.getAndIncrement() if (count < failCount) { probe.ref ! StartFailed @@ -284,7 +284,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec", ConfigFactory.parseStri class FailingUnhandledTestSetup(strategy: SupervisorStrategy) { val probe = TestProbe[AnyRef]("evt") - def behv = supervise(deferred[Command] { _ ⇒ + def behv = supervise(setup[Command] { _ ⇒ probe.ref ! StartFailed throw new TE("construction failed") }).onFailure[IllegalArgumentException](strategy) @@ -449,7 +449,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec", ConfigFactory.parseStri val strategy = SupervisorStrategy .restartWithBackoff(minBackoff, 10.seconds, 0.0) .withResetBackoffAfter(10.seconds) - val behv = Behaviors.supervise(Behaviors.deferred[Command] { _ ⇒ + val behv = Behaviors.supervise(Behaviors.setup[Command] { _ ⇒ startedProbe.ref ! Started targetBehavior(probe.ref) }).onFailure[Exception](strategy) @@ -520,7 +520,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec", ConfigFactory.parseStri "create underlying deferred behavior immediately" in { val probe = TestProbe[Event]("evt") - val behv = supervise(deferred[Command] { _ ⇒ + val behv = supervise(setup[Command] { _ ⇒ probe.ref ! Started targetBehavior(probe.ref) }).onFailure[Exception](SupervisorStrategy.restart) @@ -632,8 +632,8 @@ class SupervisionSpec extends TestKit("SupervisionSpec", ConfigFactory.parseStri "work with nested supervisions and defers" in { val strategy = SupervisorStrategy.restartWithLimit(3, 1.second) val probe = TestProbe[AnyRef]("p") - val beh = supervise[String](deferred(ctx ⇒ - supervise[String](deferred { ctx ⇒ + val beh = supervise[String](setup(ctx ⇒ + supervise[String](setup { ctx ⇒ probe.ref ! Started scaladsl.Behaviors.empty[String] }).onFailure[RuntimeException](strategy) diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/WatchSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/WatchSpec.scala index cbaf8dd9eb..ab92af8777 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/WatchSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/WatchSpec.scala @@ -73,7 +73,7 @@ class WatchSpec extends TestKit("WordSpec", WatchSpec.config) case class Failed(t: Terminated) // we need to wrap it as it is handled specially val probe = TestProbe[Any]() val ex = new TestException("boom") - val parent = spawn(Behaviors.deferred[Any] { ctx ⇒ + val parent = spawn(Behaviors.setup[Any] { ctx ⇒ val child = ctx.spawn(Behaviors.immutable[Any]((ctx, msg) ⇒ throw ex ), "child") @@ -99,8 +99,8 @@ class WatchSpec extends TestKit("WordSpec", WatchSpec.config) case class Failed(t: Terminated) // we need to wrap it as it is handled specially val probe = TestProbe[Any]() val ex = new TestException("boom") - val grossoBosso = spawn(Behaviors.deferred[Any] { ctx ⇒ - val middleManagement = ctx.spawn(Behaviors.deferred[Any] { ctx ⇒ + val grossoBosso = spawn(Behaviors.setup[Any] { ctx ⇒ + val middleManagement = ctx.spawn(Behaviors.setup[Any] { ctx ⇒ val sixPackJoe = ctx.spawn(Behaviors.immutable[Any]((ctx, msg) ⇒ throw ex ), "joe") diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorContextAskSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorContextAskSpec.scala index d3202c9aec..41ef9bdead 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorContextAskSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorContextAskSpec.scala @@ -47,7 +47,7 @@ class ActorContextAskSpec extends TestKit(ActorContextAskSpec.config) with Typed val probe = TestProbe[AnyRef]() - val snitch = Behaviors.deferred[Pong] { (ctx) ⇒ + val snitch = Behaviors.setup[Pong] { (ctx) ⇒ // Timeout comes from TypedAkkaSpec @@ -86,7 +86,7 @@ class ActorContextAskSpec extends TestKit(ActorContextAskSpec.config) with Typed } )) - val snitch = Behaviors.deferred[AnyRef] { (ctx) ⇒ + val snitch = Behaviors.setup[AnyRef] { (ctx) ⇒ ctx.ask(pingPong)(Ping) { case Success(msg) ⇒ throw new NotImplementedError(msg.toString) case Failure(x) ⇒ x @@ -114,7 +114,7 @@ class ActorContextAskSpec extends TestKit(ActorContextAskSpec.config) with Typed "deal with timeouts in ask" in { val probe = TestProbe[AnyRef]() - val snitch = Behaviors.deferred[AnyRef] { (ctx) ⇒ + val snitch = Behaviors.setup[AnyRef] { (ctx) ⇒ ctx.ask[String, String](system.deadLetters)(ref ⇒ "boo") { case Success(m) ⇒ m diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala index 522d7bfd2e..c681bddfab 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala @@ -28,7 +28,7 @@ class ActorLoggingSpec extends TestKit(ConfigFactory.parseString( "be conveniently available from the ctx" in { val actor = EventFilter.info("Started", source = "akka://ActorLoggingSpec/user/the-actor", occurrences = 1).intercept { - spawn(Behaviors.deferred[String] { ctx ⇒ + spawn(Behaviors.setup[String] { ctx ⇒ ctx.log.info("Started") Behaviors.immutable { (ctx, msg) ⇒ @@ -47,7 +47,7 @@ class ActorLoggingSpec extends TestKit(ConfigFactory.parseString( EventFilter.custom({ case event: LogEventWithMarker if event.marker == marker ⇒ true }, occurrences = 5).intercept( - spawn(Behaviors.deferred[Any] { ctx ⇒ + spawn(Behaviors.setup[Any] { ctx ⇒ ctx.log.debug(marker, "whatever") ctx.log.info(marker, "whatever") ctx.log.warning(marker, "whatever") @@ -62,7 +62,7 @@ class ActorLoggingSpec extends TestKit(ConfigFactory.parseString( EventFilter.custom({ case event: LogEventWithCause if event.cause == cause ⇒ true }, occurrences = 2).intercept( - spawn(Behaviors.deferred[Any] { ctx ⇒ + spawn(Behaviors.setup[Any] { ctx ⇒ ctx.log.warning(cause, "whatever") ctx.log.warning(marker, cause, "whatever") Behaviors.stopped @@ -77,7 +77,7 @@ class ActorLoggingSpec extends TestKit(ConfigFactory.parseString( EventFilter.custom({ case _ ⇒ true // any is fine, we're just after the right count of statements reaching the listener }, occurrences = 72).intercept { - spawn(Behaviors.deferred[String] { ctx ⇒ + spawn(Behaviors.setup[String] { ctx ⇒ ctx.log.debug("message") ctx.log.debug("{}", "arg1") ctx.log.debug("{} {}", "arg1", "arg2") @@ -180,7 +180,7 @@ class ActorLoggingSpec extends TestKit(ConfigFactory.parseString( ) else Map("txId" -> msg.transactionId) }, - Behaviors.deferred { ctx ⇒ + Behaviors.setup { ctx ⇒ ctx.log.info("Starting") Behaviors.immutable { (ctx, msg) ⇒ ctx.log.info("Got message!") diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/GracefulStopSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/GracefulStopSpec.scala index 39e666e204..8e068ce758 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/GracefulStopSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/GracefulStopSpec.scala @@ -17,7 +17,7 @@ final class GracefulStopSpec extends TestKit with TypedAkkaSpecWithShutdown { val probe = TestProbe[String]("probe") val behavior = - Behaviors.deferred[akka.NotUsed] { context ⇒ + Behaviors.setup[akka.NotUsed] { context ⇒ val c1 = context.spawn[NotUsed](Behaviors.onSignal { case (_, PostStop) ⇒ probe.ref ! "child-done" @@ -50,7 +50,7 @@ final class GracefulStopSpec extends TestKit with TypedAkkaSpecWithShutdown { val probe = TestProbe[Done]("probe") val behavior = - Behaviors.deferred[akka.NotUsed] { context ⇒ + Behaviors.setup[akka.NotUsed] { context ⇒ // do not spawn any children Behaviors.stopped { Behaviors.onSignal { diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/MessageAdapterSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/MessageAdapterSpec.scala index 7ccb2e76f2..7eef7caabf 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/MessageAdapterSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/MessageAdapterSpec.scala @@ -56,7 +56,7 @@ class MessageAdapterSpec extends TestKit(MessageAdapterSpec.config) with TypedAk val probe = TestProbe[AnotherPong]() - val snitch = Behaviors.deferred[AnotherPong] { (ctx) ⇒ + val snitch = Behaviors.setup[AnotherPong] { (ctx) ⇒ val replyTo = ctx.messageAdapter[Response](_ ⇒ AnotherPong(ctx.self.path.name, Thread.currentThread().getName)) @@ -109,7 +109,7 @@ class MessageAdapterSpec extends TestKit(MessageAdapterSpec.config) with TypedAk val probe = TestProbe[Wrapped]() - val snitch = Behaviors.deferred[Wrapped] { (ctx) ⇒ + val snitch = Behaviors.setup[Wrapped] { (ctx) ⇒ ctx.messageAdapter[Response](pong ⇒ Wrapped(qualifier = "wrong", pong)) // this is replaced val replyTo1: ActorRef[Response] = ctx.messageAdapter(pong ⇒ Wrapped(qualifier = "1", pong)) @@ -154,7 +154,7 @@ class MessageAdapterSpec extends TestKit(MessageAdapterSpec.config) with TypedAk val probe = TestProbe[Wrapped]() - val snitch = Behaviors.deferred[Wrapped] { (ctx) ⇒ + val snitch = Behaviors.setup[Wrapped] { (ctx) ⇒ val replyTo1 = ctx.messageAdapter[Pong1](pong ⇒ Wrapped(qualifier = "1", pong)) pingPong ! Ping1(replyTo1) @@ -191,7 +191,7 @@ class MessageAdapterSpec extends TestKit(MessageAdapterSpec.config) with TypedAk val probe = TestProbe[Any]() - val snitch = Behaviors.deferred[Wrapped] { (ctx) ⇒ + val snitch = Behaviors.setup[Wrapped] { (ctx) ⇒ var count = 0 val replyTo = ctx.messageAdapter[Pong] { pong ⇒ diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/OnSignalSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/OnSignalSpec.scala index 2ddd024ead..962b2bce5e 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/OnSignalSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/OnSignalSpec.scala @@ -14,7 +14,7 @@ final class OnSignalSpec extends TestKit with TypedAkkaSpecWithShutdown { "must correctly install the signal handler" in { val probe = TestProbe[Done]("probe") val behavior = - Behaviors.deferred[Nothing] { context ⇒ + Behaviors.setup[Nothing] { context ⇒ val stoppedChild = context.spawn(Behaviors.stopped, "stopped-child") context.watch(stoppedChild) Behaviors.onSignal[Nothing] { diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashBufferSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashBufferSpec.scala index dd0a22f8b6..88123eca89 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashBufferSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashBufferSpec.scala @@ -113,7 +113,7 @@ class StashBufferSpec extends WordSpec with Matchers { valueInbox.ref ! state Behaviors.same } else { - Behaviors.deferred[String](_ ⇒ behavior(state + msg)) + Behaviors.setup[String](_ ⇒ behavior(state + msg)) } } diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashSpec.scala index cff84528b0..f6fc32b176 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/StashSpec.scala @@ -19,7 +19,7 @@ object StashSpec { final case class GetStashSize(replyTo: ActorRef[Int]) extends Command val immutableStash: Behavior[Command] = - Behaviors.deferred[Command] { _ ⇒ + Behaviors.setup[Command] { _ ⇒ val buffer = StashBuffer[Command](capacity = 10) def active(processed: Vector[String]): Behavior[Command] = diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/adapter/AdapterSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/adapter/AdapterSpec.scala index de559a3f8b..fa71c68e65 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/adapter/AdapterSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/adapter/AdapterSpec.scala @@ -162,7 +162,7 @@ class AdapterSpec extends AkkaSpec { for { _ ← 0 to 10 } { var system: akka.actor.typed.ActorSystem[NotUsed] = null try { - system = ActorSystem.create(Behaviors.deferred[NotUsed](_ ⇒ Behavior.stopped[NotUsed]), "AdapterSpec-stopping-guardian") + system = ActorSystem.create(Behaviors.setup[NotUsed](_ ⇒ Behavior.stopped[NotUsed]), "AdapterSpec-stopping-guardian") } finally if (system != null) shutdown(system.toUntyped) } } diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/FaultToleranceDocSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/FaultToleranceDocSpec.scala index c259291055..cdce0e7dc1 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/FaultToleranceDocSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/FaultToleranceDocSpec.scala @@ -30,7 +30,7 @@ class FaultToleranceDocSpec extends TestKit(ConfigFactory.parseString( } } - val middleManagementBehavior = Behaviors.deferred[Message] { ctx ⇒ + val middleManagementBehavior = Behaviors.setup[Message] { ctx ⇒ ctx.log.info("Middle management starting up") val child = ctx.spawn(worker, "child") ctx.watch(child) @@ -44,7 +44,7 @@ class FaultToleranceDocSpec extends TestKit(ConfigFactory.parseString( } } - val bossBehavior = Behaviors.supervise(Behaviors.deferred[Message] { ctx ⇒ + val bossBehavior = Behaviors.supervise(Behaviors.setup[Message] { ctx ⇒ ctx.log.info("Boss starting up") val middleManagment = ctx.spawn(middleManagementBehavior, "middle-management") ctx.watch(middleManagment) diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/InteractionPatternsSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/InteractionPatternsSpec.scala index f9f7f43d1e..92a8f6eb16 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/InteractionPatternsSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/InteractionPatternsSpec.scala @@ -101,7 +101,7 @@ class InteractionPatternsSpec extends TestKit with TypedAkkaSpecWithShutdown { private final case class WrappedBackendResponse(response: Backend.Response) extends Command def translator(backend: ActorRef[Backend.Request]): Behavior[Command] = - Behaviors.deferred[Command] { ctx ⇒ + Behaviors.setup[Command] { ctx ⇒ val backendResponseMapper: ActorRef[Backend.Response] = ctx.messageAdapter(rsp ⇒ WrappedBackendResponse(rsp)) @@ -224,7 +224,7 @@ class InteractionPatternsSpec extends TestKit with TypedAkkaSpecWithShutdown { // this is a part of the protocol that is internal to the actor itself case class AdaptedResponse(message: String) extends DaveMessage - def daveBehavior(hal: ActorRef[HalCommand]) = Behaviors.deferred[DaveMessage] { ctx ⇒ + def daveBehavior(hal: ActorRef[HalCommand]) = Behaviors.setup[DaveMessage] { ctx ⇒ // asking someone requires a timeout, if the timeout hits without response // the ask is failed with a TimeoutException @@ -321,7 +321,7 @@ class InteractionPatternsSpec extends TestKit with TypedAkkaSpecWithShutdown { // we don't _really_ care about the actor protocol here as nobody will send us // messages except for responses to our queries, so we just accept any kind of message // but narrow that to more limited types then we interact - Behaviors.deferred[AnyRef] { ctx ⇒ + Behaviors.setup[AnyRef] { ctx ⇒ var wallet: Option[Wallet] = None var keys: Option[Keys] = None diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala index 2ae08cb778..3e97794a06 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala @@ -151,7 +151,7 @@ class IntroSpec extends TestKit with TypedAkkaSpecWithShutdown { //#chatroom-main val main: Behavior[NotUsed] = - Behaviors.deferred { ctx ⇒ + Behaviors.setup { ctx ⇒ val chatRoom = ctx.spawn(ChatRoom.behavior, "chatroom") val gabblerRef = ctx.spawn(gabbler, "gabbler") ctx.watch(gabblerRef) diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala index 0a32a0386e..d46a9893c9 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala @@ -114,7 +114,7 @@ class MutableIntroSpec extends TestKit with TypedAkkaSpecWithShutdown { //#chatroom-main val main: Behavior[String] = - Behaviors.deferred { ctx ⇒ + Behaviors.setup { ctx ⇒ val chatRoom = ctx.spawn(ChatRoom.behavior(), "chatroom") val gabblerRef = ctx.spawn(gabbler, "gabbler") ctx.watch(gabblerRef) diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StashDocSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StashDocSpec.scala index 51e0ef202d..a1aed29287 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StashDocSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StashDocSpec.scala @@ -34,7 +34,7 @@ object StashDocSpec { private final case class DBError(cause: Throwable) extends Command def behavior(id: String, db: DB): Behavior[Command] = - Behaviors.deferred[Command] { ctx ⇒ + Behaviors.setup[Command] { ctx ⇒ val buffer = StashBuffer[Command](capacity = 100) diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/TypedWatchingUntypedSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/TypedWatchingUntypedSpec.scala index a3b29177b0..f4baae0814 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/TypedWatchingUntypedSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/TypedWatchingUntypedSpec.scala @@ -23,7 +23,7 @@ object TypedWatchingUntypedSpec { case object Pong extends Command val behavior: Behavior[Command] = - Behaviors.deferred { context ⇒ + Behaviors.setup { context ⇒ // context.spawn is an implicit extension method val untyped = context.actorOf(Untyped.props(), "second") diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala index 726a6a54ad..828a65e7b4 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala @@ -182,7 +182,7 @@ object Behavior { @InternalApi private[akka] final case class DeferredBehavior[T](factory: SAC[T] ⇒ Behavior[T]) extends Behavior[T] { - /** "undefer" the deferred behavior */ + /** start the deferred behavior */ @throws(classOf[Exception]) def apply(ctx: ActorContext[T]): Behavior[T] = factory(ctx.asScala) @@ -227,7 +227,7 @@ object Behavior { /** * INTERNAL API * - * Return special behaviors as is, undefer deferred, if behavior is "non-special" apply the wrap function `f` to get + * Return special behaviors as is, start deferred, if behavior is "non-special" apply the wrap function `f` to get * and return the result from that. Useful for cases where a [[Behavior]] implementation that is decorating another * behavior has processed a message and needs to re-wrap the resulting behavior with itself. */ @@ -238,14 +238,18 @@ object Behavior { case SameBehavior | `currentBehavior` ⇒ same case UnhandledBehavior ⇒ unhandled case StoppedBehavior ⇒ stopped - case deferred: DeferredBehavior[T] ⇒ wrap(currentBehavior, undefer(deferred, ctx), ctx)(f) + case deferred: DeferredBehavior[T] ⇒ wrap(currentBehavior, start(deferred, ctx), ctx)(f) case other ⇒ f(other) } + /** + * Starts deferred behavior and nested deferred behaviors until a non deferred behavior is reached + * and that is then returned. + */ @tailrec - def undefer[T](behavior: Behavior[T], ctx: ActorContext[T]): Behavior[T] = { + def start[T](behavior: Behavior[T], ctx: ActorContext[T]): Behavior[T] = { behavior match { - case innerDeferred: DeferredBehavior[T] ⇒ undefer(innerDeferred(ctx), ctx) + case innerDeferred: DeferredBehavior[T] ⇒ start(innerDeferred(ctx), ctx) case _ ⇒ behavior } } @@ -302,7 +306,7 @@ object Behavior { throw new IllegalArgumentException(s"cannot execute with [$behavior] as behavior") case _: UntypedBehavior[_] ⇒ throw new IllegalArgumentException(s"cannot wrap behavior [$behavior] in " + - "Actor.deferred, Actor.supervise or similar") + "Behaviors.setup, Behaviors.supervise or similar") case d: DeferredBehavior[_] ⇒ throw new IllegalArgumentException(s"deferred [$d] should not be passed to interpreter") case IgnoreBehavior ⇒ SameBehavior.asInstanceOf[Behavior[T]] case s: StoppedBehavior[T] ⇒ s @@ -312,7 +316,7 @@ object Behavior { case signal: Signal ⇒ ext.receiveSignal(ctx, signal) case m ⇒ ext.receiveMessage(ctx, m.asInstanceOf[T]) } - undefer(possiblyDeferredResult, ctx) + start(possiblyDeferredResult, ctx) } /** @@ -323,7 +327,7 @@ object Behavior { */ @InternalApi private[akka] def interpretMessages[T](behavior: Behavior[T], ctx: ActorContext[T], messages: Iterator[T]): Behavior[T] = { @tailrec def interpretOne(b: Behavior[T]): Behavior[T] = { - val b2 = Behavior.undefer(b, ctx) + val b2 = Behavior.start(b, ctx) if (!Behavior.isAlive(b2) || !messages.hasNext) b2 else { val nextB = messages.next() match { @@ -336,7 +340,7 @@ object Behavior { } } - interpretOne(Behavior.undefer(behavior, ctx)) + interpretOne(Behavior.start(behavior, ctx)) } } diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/BehaviorImpl.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/BehaviorImpl.scala index bd996bfafb..8931abb11c 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/BehaviorImpl.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/BehaviorImpl.scala @@ -29,7 +29,7 @@ import scala.reflect.ClassTag case d: DeferredBehavior[T] ⇒ DeferredBehavior[U] { ctx ⇒ val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]] - val b = Behavior.validateAsInitial(Behavior.undefer(d, c)) + val b = Behavior.validateAsInitial(Behavior.start(d, c)) Widened(b, matcher) } case _ ⇒ @@ -109,7 +109,7 @@ import scala.reflect.ClassTag case d: DeferredBehavior[T] ⇒ DeferredBehavior[T] { ctx ⇒ val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]] - val b = Behavior.validateAsInitial(Behavior.undefer(d, c)) + val b = Behavior.validateAsInitial(Behavior.start(d, c)) Intercept(beforeMessage, beforeSignal, afterMessage, afterSignal, b, toStringPrefix) } case _ ⇒ diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/Restarter.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/Restarter.scala index e0e3e662f3..c9029ec0e9 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/Restarter.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/Restarter.scala @@ -23,7 +23,7 @@ import scala.util.control.NonFatal */ @InternalApi private[akka] object Supervisor { def apply[T, Thr <: Throwable: ClassTag](initialBehavior: Behavior[T], strategy: SupervisorStrategy): Behavior[T] = - Behaviors.deferred[T] { ctx ⇒ + Behaviors.setup[T] { ctx ⇒ val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]] val supervisor: Supervisor[T, Thr] = strategy match { case Restart(-1, _, loggingEnabled) ⇒ @@ -112,7 +112,7 @@ import scala.util.control.NonFatal def init(ctx: ActorContext[T]) = // no handling of errors for Resume as that could lead to infinite restart-loop - wrap(Behavior.validateAsInitial(Behavior.undefer(behavior, ctx)), afterException = false) + wrap(Behavior.validateAsInitial(Behavior.start(behavior, ctx)), afterException = false) override def handleException(ctx: ActorContext[T], startedBehavior: Behavior[T]): Catcher[Supervisor[T, Thr]] = { case NonFatal(ex: Thr) ⇒ @@ -132,7 +132,7 @@ import scala.util.control.NonFatal override val behavior: Behavior[T], override val loggingEnabled: Boolean) extends Supervisor[T, Thr] { def init(ctx: ActorContext[T]): Supervisor[T, Thr] = - wrap(Behavior.validateAsInitial(Behavior.undefer(behavior, ctx)), false) + wrap(Behavior.validateAsInitial(Behavior.start(behavior, ctx)), false) override def handleException(ctx: ActorContext[T], startedBehavior: Behavior[T]): Catcher[Behavior[T]] = { case NonFatal(ex: Thr) ⇒ @@ -154,7 +154,7 @@ import scala.util.control.NonFatal override def init(ctx: ActorContext[T]) = // no handling of errors for Restart as that could lead to infinite restart-loop - wrap(Behavior.validateAsInitial(Behavior.undefer(behavior, ctx)), afterException = false) + wrap(Behavior.validateAsInitial(Behavior.start(behavior, ctx)), afterException = false) override def handleException(ctx: ActorContext[T], startedBehavior: Behavior[T]): Catcher[Supervisor[T, Thr]] = { case NonFatal(ex: Thr) ⇒ @@ -177,7 +177,7 @@ import scala.util.control.NonFatal override def init(ctx: ActorContext[T]) = try { - wrap(Behavior.validateAsInitial(Behavior.undefer(behavior, ctx)), afterException = false) + wrap(Behavior.validateAsInitial(Behavior.start(behavior, ctx)), afterException = false) } catch { case NonFatal(ex: Thr) ⇒ log(ctx, ex) @@ -252,7 +252,7 @@ import scala.util.control.NonFatal def init(ctx: ActorContext[Any]): Supervisor[Any, Thr] = try { - val startedBehavior = Behavior.validateAsInitial(Behavior.undefer(initialBehavior, ctx)) + val startedBehavior = Behavior.validateAsInitial(Behavior.start(initialBehavior, ctx)) new BackoffRestarter(initialBehavior, startedBehavior, strategy, restartCount, blackhole) } catch { case NonFatal(ex: Thr) ⇒ diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/TimerSchedulerImpl.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/TimerSchedulerImpl.scala index 5de314eaf0..d5ed348a4d 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/TimerSchedulerImpl.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/TimerSchedulerImpl.scala @@ -26,7 +26,7 @@ import scala.reflect.ClassTag final case class TimerMsg(key: Any, generation: Int, owner: AnyRef) def withTimers[T](factory: TimerSchedulerImpl[T] ⇒ Behavior[T]): Behavior[T] = { - scaladsl.Behaviors.deferred[T] { ctx ⇒ + scaladsl.Behaviors.setup[T] { ctx ⇒ val timerScheduler = new TimerSchedulerImpl[T](ctx) val behavior = factory(timerScheduler) timerScheduler.intercept(behavior) diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorAdapter.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorAdapter.scala index d825301633..cc1a89bb48 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorAdapter.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorAdapter.scala @@ -133,7 +133,7 @@ import scala.util.control.NonFatal protected def start(): Unit = { context.become(running) initializeContext() - behavior = validateAsInitial(undefer(behavior, ctx)) + behavior = validateAsInitial(Behavior.start(behavior, ctx)) if (!isAlive(behavior)) context.stop(self) } @@ -144,7 +144,7 @@ import scala.util.control.NonFatal override def postRestart(reason: Throwable): Unit = { initializeContext() - behavior = validateAsInitial(undefer(behavior, ctx)) + behavior = validateAsInitial(Behavior.start(behavior, ctx)) if (!isAlive(behavior)) context.stop(self) } diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/receptionist/ReceptionistImpl.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/receptionist/ReceptionistImpl.scala index 783db620ae..d993e03e6b 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/receptionist/ReceptionistImpl.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/receptionist/ReceptionistImpl.scala @@ -67,7 +67,7 @@ private[akka] object ReceptionistImpl extends ReceptionistBehaviorProvider { type SubscriptionRegistry = TypedMultiMap[AbstractServiceKey, SubscriptionsKV] private[akka] def init[State](externalInterfaceFactory: ActorContext[AllCommands] ⇒ ExternalInterface[State]): Behavior[Command] = - Behaviors.deferred[AllCommands] { ctx ⇒ + Behaviors.setup[AllCommands] { ctx ⇒ val externalInterface = externalInterfaceFactory(ctx) behavior( TypedMultiMap.empty[AbstractServiceKey, KV], @@ -89,7 +89,7 @@ private[akka] object ReceptionistImpl extends ReceptionistBehaviorProvider { * FIXME: replace by simple map in our state */ def watchWith(ctx: ActorContext[AllCommands], target: ActorRef[_], msg: AllCommands): Unit = - ctx.spawnAnonymous[Nothing](Behaviors.deferred[Nothing] { innerCtx ⇒ + ctx.spawnAnonymous[Nothing](Behaviors.setup[Nothing] { innerCtx ⇒ innerCtx.watch(target) Behaviors.immutable[Nothing]((_, _) ⇒ Behaviors.same) .onSignal { diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala index 16ad932328..6f3095e1c0 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala @@ -29,17 +29,17 @@ object Behaviors { private def unitFunction[T] = _unitFunction.asInstanceOf[((SAC[T], Signal) ⇒ Unit)] /** - * `deferred` is a factory for a behavior. Creation of the behavior instance is deferred until + * `setup` is a factory for a behavior. Creation of the behavior instance is deferred until * the actor is started, as opposed to [[Behaviors#immutable]] that creates the behavior instance * immediately before the actor is running. The `factory` function pass the `ActorContext` * as parameter and that can for example be used for spawning child actors. * - * `deferred` is typically used as the outer most behavior when spawning an actor, but it + * `setup` is typically used as the outer most behavior when spawning an actor, but it * can also be returned as the next behavior when processing a message or signal. In that - * case it will be "undeferred" immediately after it is returned, i.e. next message will be - * processed by the undeferred behavior. + * case it will be started immediately after it is returned, i.e. next message will be + * processed by the started behavior. */ - def deferred[T](factory: akka.japi.function.Function[ActorContext[T], Behavior[T]]): Behavior[T] = + def setup[T](factory: akka.japi.function.Function[ActorContext[T], Behavior[T]]): Behavior[T] = Behavior.DeferredBehavior(ctx ⇒ factory.apply(ctx.asJava)) /** @@ -55,7 +55,7 @@ object Behaviors { * @return the deferred behavior */ def mutable[T](factory: akka.japi.function.Function[ActorContext[T], MutableBehavior[T]]): Behavior[T] = - deferred(factory) + setup(factory) /** * Mutable behavior can be implemented by extending this class and implement the diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala index 4436b7a3d9..5187d9d8eb 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala @@ -40,17 +40,17 @@ object Behaviors { } /** - * `deferred` is a factory for a behavior. Creation of the behavior instance is deferred until + * `setup` is a factory for a behavior. Creation of the behavior instance is deferred until * the actor is started, as opposed to [[Behaviors.immutable]] that creates the behavior instance * immediately before the actor is running. The `factory` function pass the `ActorContext` * as parameter and that can for example be used for spawning child actors. * - * `deferred` is typically used as the outer most behavior when spawning an actor, but it + * `setup` is typically used as the outer most behavior when spawning an actor, but it * can also be returned as the next behavior when processing a message or signal. In that - * case it will be "undeferred" immediately after it is returned, i.e. next message will be - * processed by the undeferred behavior. + * case it will be started immediately after it is returned, i.e. next message will be + * processed by the started behavior. */ - def deferred[T](factory: ActorContext[T] ⇒ Behavior[T]): Behavior[T] = + def setup[T](factory: ActorContext[T] ⇒ Behavior[T]): Behavior[T] = Behavior.DeferredBehavior(factory) /** @@ -61,12 +61,11 @@ object Behaviors { * function. The reason for the deferred creation is to avoid sharing the same instance in * multiple actors, and to create a new instance when the actor is restarted. * - * @param factory - * behavior factory that takes the child actor’s context as argument + * @param factory behavior factory that takes the child actor’s context as argument * @return the deferred behavior */ def mutable[T](factory: ActorContext[T] ⇒ MutableBehavior[T]): Behavior[T] = - deferred(factory) + setup(factory) /** * Mutable behavior can be implemented by extending this class and implement the diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala index e931dd1f16..5b5a82cf5e 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala @@ -35,7 +35,7 @@ import akka.actor.typed.Terminated def behavior(settings: dd.ReplicatorSettings, underlyingReplicator: Option[akka.actor.ActorRef]): Behavior[SReplicator.Command] = { - Behaviors.deferred { ctx ⇒ + Behaviors.setup { ctx ⇒ val untypedReplicator = underlyingReplicator match { case Some(ref) ⇒ ref case None ⇒ diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/AdaptedClusterImpl.scala b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/AdaptedClusterImpl.scala index 5ccf10a073..d13a645c4f 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/AdaptedClusterImpl.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/AdaptedClusterImpl.scala @@ -24,7 +24,7 @@ private[akka] object AdapterClusterImpl { private case object Up extends SeenState private case class Removed(previousStatus: MemberStatus) extends SeenState - private def subscriptionsBehavior(adaptedCluster: akka.cluster.Cluster) = Behaviors.deferred[ClusterStateSubscription] { ctx ⇒ + private def subscriptionsBehavior(adaptedCluster: akka.cluster.Cluster) = Behaviors.setup[ClusterStateSubscription] { ctx ⇒ var seenState: SeenState = BeforeUp var upSubscribers: List[ActorRef[SelfUp]] = Nil var removedSubscribers: List[ActorRef[SelfRemoved]] = Nil diff --git a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/ReceptionistExampleTest.java b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/ReceptionistExampleTest.java index b9839ce061..7242e43d96 100644 --- a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/ReceptionistExampleTest.java +++ b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/ReceptionistExampleTest.java @@ -29,7 +29,7 @@ public class ReceptionistExampleTest extends JUnitSuite { } static Behavior pingService() { - return Behaviors.deferred((ctx) -> { + return Behaviors.setup((ctx) -> { ctx.getSystem().receptionist() .tell(new Receptionist.Register<>(PingServiceKey, ctx.getSelf(), ctx.getSystem().deadLetters())); return Behaviors.immutable(Ping.class) @@ -43,7 +43,7 @@ public class ReceptionistExampleTest extends JUnitSuite { //#pinger static Behavior pinger(ActorRef pingService) { - return Behaviors.deferred((ctx) -> { + return Behaviors.setup((ctx) -> { pingService.tell(new Ping(ctx.getSelf())); return Behaviors.immutable(Pong.class) .onMessage(Pong.class, (c, msg) -> { @@ -56,7 +56,7 @@ public class ReceptionistExampleTest extends JUnitSuite { //#pinger-guardian static Behavior> guardian() { - return Behaviors.deferred((ctx) -> { + return Behaviors.setup((ctx) -> { ctx.getSystem().receptionist() .tell(new Receptionist.Subscribe<>(PingServiceKey, ctx.getSelf())); ActorRef ps = ctx.spawnAnonymous(pingService()); diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorSpec.scala index ff171d4a1d..80ac1508ba 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorSpec.scala @@ -43,7 +43,7 @@ object ReplicatorSpec { val Key = GCounterKey("counter") def client(replicator: ActorRef[Replicator.Command])(implicit cluster: Cluster): Behavior[ClientCommand] = - Behaviors.deferred[ClientCommand] { ctx ⇒ + Behaviors.setup[ClientCommand] { ctx ⇒ val updateResponseAdapter: ActorRef[Replicator.UpdateResponse[GCounter]] = ctx.messageAdapter(InternalUpdateResponse.apply) diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala index cdea425065..82358bf3d1 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala @@ -108,7 +108,7 @@ class RemoteContextAskSpec extends TestKit(RemoteContextAskSpec.config) with Typ // wait until the service is seen on the first node val remoteRef = node1Probe.expectMessageType[Receptionist.Listing[Ping]].serviceInstances.head - spawn(Behaviors.deferred[AnyRef] { (ctx) ⇒ + spawn(Behaviors.setup[AnyRef] { (ctx) ⇒ implicit val timeout: Timeout = 3.seconds ctx.ask(remoteRef)(Ping) { diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala index c7020e6f99..27033d501f 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala @@ -62,7 +62,7 @@ class RemoteDeployNotAllowedSpec extends TestKit(RemoteDeployNotAllowedSpec.conf // this should throw try { ctx.spawn( - Behaviors.deferred[AnyRef] { ctx ⇒ Behaviors.empty }, + Behaviors.setup[AnyRef] { ctx ⇒ Behaviors.empty }, name) } catch { case ex: Exception ⇒ probe.ref ! ex @@ -72,7 +72,7 @@ class RemoteDeployNotAllowedSpec extends TestKit(RemoteDeployNotAllowedSpec.conf case SpawnAnonymous ⇒ // this should throw try { - ctx.spawnAnonymous(Behaviors.deferred[AnyRef] { ctx ⇒ Behaviors.empty }) + ctx.spawnAnonymous(Behaviors.setup[AnyRef] { ctx ⇒ Behaviors.empty }) } catch { case ex: Exception ⇒ probe.ref ! ex } diff --git a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExampleSpec.scala b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExampleSpec.scala index 80b659d0da..39236514ec 100644 --- a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExampleSpec.scala +++ b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExampleSpec.scala @@ -18,7 +18,7 @@ import scala.collection.immutable.Set object RandomRouter { def router[T](serviceKey: ServiceKey[T]): Behavior[T] = - Behaviors.deferred[Any] { ctx ⇒ + Behaviors.setup[Any] { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(serviceKey, ctx.self) def routingBehavior(routees: Vector[ActorRef[T]]): Behavior[Any] = @@ -45,7 +45,7 @@ object RandomRouter { // same as above, but also subscribes to cluster reachability events and // avoids routees that are unreachable def clusterRouter[T](serviceKey: ServiceKey[T]): Behavior[T] = - Behaviors.deferred[Any] { ctx ⇒ + Behaviors.setup[Any] { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(serviceKey, ctx.self) val cluster = Cluster(ctx.system) @@ -93,7 +93,7 @@ object PingPongExample { final case object Pong val pingService: Behavior[Ping] = - Behaviors.deferred { ctx ⇒ + Behaviors.setup { ctx ⇒ ctx.system.receptionist ! Receptionist.Register(PingServiceKey, ctx.self, ctx.system.deadLetters) Behaviors.immutable[Ping] { (_, msg) ⇒ msg match { @@ -106,7 +106,7 @@ object PingPongExample { //#ping-service //#pinger - def pinger(pingService: ActorRef[Ping]) = Behaviors.deferred[Pong.type] { ctx ⇒ + def pinger(pingService: ActorRef[Ping]) = Behaviors.setup[Pong.type] { ctx ⇒ pingService ! Ping(ctx.self) Behaviors.immutable { (_, msg) ⇒ println("I was ponged!!" + msg) @@ -116,7 +116,7 @@ object PingPongExample { //#pinger //#pinger-guardian - val guardian: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ + val guardian: Behavior[Listing[Ping]] = Behaviors.setup { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(PingServiceKey, ctx.self) val ps = ctx.spawnAnonymous(pingService) ctx.watch(ps) @@ -133,7 +133,7 @@ object PingPongExample { //#pinger-guardian //#pinger-guardian-pinger-service - val guardianJustPingService: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ + val guardianJustPingService: Behavior[Listing[Ping]] = Behaviors.setup { ctx ⇒ val ps = ctx.spawnAnonymous(pingService) ctx.watch(ps) Behaviors.immutablePartial[Listing[Ping]] { @@ -149,7 +149,7 @@ object PingPongExample { //#pinger-guardian-pinger-service //#pinger-guardian-just-pinger - val guardianJustPinger: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ + val guardianJustPinger: Behavior[Listing[Ping]] = Behaviors.setup { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(PingServiceKey, ctx.self) Behaviors.immutablePartial[Listing[Ping]] { case (c, Listing(PingServiceKey, listings)) if listings.nonEmpty ⇒ diff --git a/akka-docs/src/main/paradox/typed/actors.md b/akka-docs/src/main/paradox/typed/actors.md index 3f390862bd..dc5fed093c 100644 --- a/akka-docs/src/main/paradox/typed/actors.md +++ b/akka-docs/src/main/paradox/typed/actors.md @@ -252,10 +252,10 @@ particular one using the `immutable` behavior decorator. The provided `onSignal` function will be invoked for signals (subclasses of `Signal`) or the `onMessage` function for user messages. -This particular `main` Actor is created using `Behaviors.deferred`, which is like a factory for a behavior. +This particular `main` Actor is created using `Behaviors.onStart`, which is like a factory for a behavior. Creation of the behavior instance is deferred until the actor is started, as opposed to `Behaviors.immutable` that creates the behavior instance immediately before the actor is running. The factory function in -`deferred` pass the `ActorContext` as parameter and that can for example be used for spawning child actors. +`onStart` is passed the `ActorContext` as parameter and that can for example be used for spawning child actors. This `main` Actor creates the chat room and the gabbler and the session between them is initiated, and when the gabbler is finished we will receive the `Terminated` event due to having called `ctx.watch` for it. This allows us to shut down the Actor system: when diff --git a/akka-docs/src/main/paradox/typed/interaction-patterns.md b/akka-docs/src/main/paradox/typed/interaction-patterns.md index f3581d22c5..4d77b512e9 100644 --- a/akka-docs/src/main/paradox/typed/interaction-patterns.md +++ b/akka-docs/src/main/paradox/typed/interaction-patterns.md @@ -107,7 +107,7 @@ their registration order, i.e. the last registered first. A message adapter (and the returned `ActorRef`) has the same lifecycle as the receiving actor. It's recommended to register the adapters in a top level -`Behaviors.deferred` or constructor of `MutableBehavior` but it's possible to +`Behaviors.setup` or constructor of `MutableBehavior` but it's possible to register them later also if needed. The adapter function is running in the receiving actor and can safely access state of it, but if it throws an exception the actor is stopped. diff --git a/akka-docs/src/main/paradox/typed/persistence.md b/akka-docs/src/main/paradox/typed/persistence.md index f2b077feb9..46c309a79e 100644 --- a/akka-docs/src/main/paradox/typed/persistence.md +++ b/akka-docs/src/main/paradox/typed/persistence.md @@ -231,6 +231,6 @@ Java ## Current limitations -* The `PersistentBehavior` can't be wrapped in other behaviors, such as `Behaviors.deferred`. See [#23694](https://github.com/akka/akka/issues/23694) +* The `PersistentBehavior` can't be wrapped in other behaviors, such as `Behaviors.setup`. See [#23694](https://github.com/akka/akka/issues/23694) diff --git a/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala b/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala index 6a523892a8..845f43b63c 100644 --- a/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala +++ b/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala @@ -267,7 +267,7 @@ object PersistentActorCompileOnlyTest { def isFullyHydrated(basket: Basket, ids: List[Id]) = basket.items.map(_.id) == ids - Behaviors.deferred { ctx: ActorContext[Command] ⇒ + Behaviors.setup { ctx: ActorContext[Command] ⇒ // FIXME this doesn't work, wrapping not supported var basket = Basket(Nil) diff --git a/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorSpec.scala b/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorSpec.scala index 22a30746ef..c36217fa14 100644 --- a/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorSpec.scala +++ b/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorSpec.scala @@ -362,7 +362,7 @@ class PersistentActorSpec extends TestKit(PersistentActorSpec.config) with Event def watcher(toWatch: ActorRef[_]): TestProbe[String] = { val probe = TestProbe[String]() - val w = Behaviors.deferred[Any] { (ctx) ⇒ + val w = Behaviors.setup[Any] { (ctx) ⇒ ctx.watch(toWatch) Behaviors.immutable[Any] { (_, _) ⇒ Behaviors.same } .onSignal { diff --git a/akka-testkit-typed/src/main/scala/akka/testkit/typed/BehaviorTestkit.scala b/akka-testkit-typed/src/main/scala/akka/testkit/typed/BehaviorTestkit.scala index 2b8f9678c5..220bc42c9e 100644 --- a/akka-testkit-typed/src/main/scala/akka/testkit/typed/BehaviorTestkit.scala +++ b/akka-testkit-typed/src/main/scala/akka/testkit/typed/BehaviorTestkit.scala @@ -177,7 +177,7 @@ class BehaviorTestkit[T] private (_name: String, _initialBehavior: Behavior[T]) } } - private var current = Behavior.validateAsInitial(Behavior.undefer(_initialBehavior, ctx)) + private var current = Behavior.validateAsInitial(Behavior.start(_initialBehavior, ctx)) def currentBehavior: Behavior[T] = current def isAlive: Boolean = Behavior.isAlive(current)