From 14c6440cee1fcc9a325e88303384cced3a1641b8 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Wed, 17 Jan 2018 10:29:45 +0100 Subject: [PATCH] Rename scaladsl/javadsl Actor to Behaviors, #24071 * The technical reason for not naming it Behavior is that it would be duplicate import conflicts of akka.actor.typed.Behavior and akka.actor.typed.scaladsl.Behavior * Plural naming is pretty common for factories like this, e.g. java.util.Collections --- .../actor/typed/javadsl/ActorCompile.java | 12 +- .../akka/actor/typed/javadsl/AdapterTest.java | 4 +- .../typed/javadsl/BehaviorBuilderTest.java | 10 +- .../typed/javadsl/ReceiveBuilderTest.java | 10 +- .../akka/actor/typed/javadsl/WatchTest.java | 3 +- .../test/java/jdocs/akka/typed/IntroTest.java | 24 ++-- .../jdocs/akka/typed/MutableIntroTest.java | 10 +- .../coexistence/TypedWatchingUntypedTest.java | 8 +- .../coexistence/UntypedWatchingTypedTest.java | 6 +- .../testing/async/BasicAsyncTestingTest.java | 6 +- .../testing/sync/BasicSyncTestingTest.java | 14 +- .../akka/actor/typed/ActorContextSpec.scala | 128 +++++++++--------- .../test/scala/akka/actor/typed/AskSpec.scala | 8 +- .../scala/akka/actor/typed/BehaviorSpec.scala | 4 +- .../scala/akka/actor/typed/DeferredSpec.scala | 38 +++--- .../scala/akka/actor/typed/StepWise.scala | 2 +- .../akka/actor/typed/SupervisionSpec.scala | 30 ++-- .../scala/akka/actor/typed/TimerSpec.scala | 30 ++-- .../scala/akka/actor/typed/WatchSpec.scala | 18 +-- .../typed/internal/ActorSystemSpec.scala | 22 +-- .../internal/MiscMessageSerializerSpec.scala | 4 +- .../receptionist/LocalReceptionistSpec.scala | 8 +- .../typed/scaladsl/ImmutablePartialSpec.scala | 4 +- .../actor/typed/scaladsl/OnSignalSpec.scala | 8 +- .../typed/scaladsl/adapter/AdapterSpec.scala | 32 ++--- .../scala/docs/akka/typed/IntroSpec.scala | 35 +++-- .../docs/akka/typed/MutableIntroSpec.scala | 22 +-- .../TypedWatchingUntypedSpec.scala | 10 +- .../UntypedWatchingTypedSpec.scala | 6 +- .../testing/async/BasicAsyncTestingSpec.scala | 6 +- .../testing/sync/BasicSyncTestingSpec.scala | 16 +-- .../scala/akka/actor/typed/Behavior.scala | 4 +- .../akka/actor/typed/internal/Restarter.scala | 6 +- .../typed/internal/TimerSchedulerImpl.scala | 2 +- .../receptionist/ReceptionistImpl.scala | 16 +-- .../javadsl/{Actor.scala => Behaviors.scala} | 13 +- .../actor/typed/javadsl/ReceiveBuilder.scala | 8 +- .../scaladsl/{Actor.scala => Behaviors.scala} | 13 +- .../ClusterShardingPersistenceSpec.scala | 6 +- .../sharding/typed/ClusterShardingSpec.scala | 18 +-- .../typed/internal/ReplicatorBehavior.scala | 30 ++-- .../typed/internal/AdaptedClusterImpl.scala | 32 ++--- .../ddata/typed/javadsl/ReplicatorTest.java | 8 +- .../typed/BasicClusterExampleTest.java | 8 +- .../typed/ReceptionistExampleTest.java | 20 +-- .../ddata/typed/scaladsl/ReplicatorSpec.scala | 18 +-- .../typed/ClusterSingletonApiSpec.scala | 8 +- .../ClusterSingletonPersistenceSpec.scala | 6 +- .../cluster/typed/RemoteMessageSpec.scala | 10 +- .../ClusterReceptionistSpec.scala | 8 +- .../typed/BasicClusterExampleSpec.scala | 14 +- .../typed/ReceptionistExampleSpec.scala | 50 +++---- akka-docs/src/main/paradox/actors-typed.md | 4 +- .../src/main/paradox/persistence-typed.md | 28 ++-- .../typed/internal/PersistentActorImpl.scala | 4 +- ...tActor.scala => PersistentBehaviors.scala} | 6 +- .../PersistentActorCompileOnlyTest.scala | 26 ++-- .../typed/scaladsl/PersistentActorSpec.scala | 14 +- ...ala => BasicPersistentBehaviorsSpec.scala} | 10 +- ...la => InDepthPersistentBehaviorSpec.scala} | 10 +- .../testkit/typed/TestEventListener.scala | 20 +-- .../scala/akka/testkit/typed/TestKit.scala | 8 +- .../testkit/typed/scaladsl/TestProbe.scala | 6 +- .../testkit/typed/BehaviorTestkitSpec.scala | 20 +-- 64 files changed, 501 insertions(+), 491 deletions(-) rename akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/{Actor.scala => Behaviors.scala} (98%) rename akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/{Actor.scala => Behaviors.scala} (96%) rename akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/{PersistentActor.scala => PersistentBehaviors.scala} (98%) rename akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/{BasicPersistentActorSpec.scala => BasicPersistentBehaviorsSpec.scala} (78%) rename akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/{InDepthPersistentActorSpec.scala => InDepthPersistentBehaviorSpec.scala} (93%) 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 3c8acbb6e8..8ad57f35ce 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 @@ -6,7 +6,7 @@ package akka.actor.typed.javadsl; import akka.actor.typed.*; import akka.actor.typed.ActorContext; -import static akka.actor.typed.javadsl.Actor.*; +import static akka.actor.typed.javadsl.Behaviors.*; import java.util.concurrent.TimeUnit; import scala.concurrent.duration.Duration; @@ -48,7 +48,7 @@ public class ActorCompile { ActorSystem system = ActorSystem.create(actor1, "Sys"); { - Actor.immutable((ctx, msg) -> { + Behaviors.immutable((ctx, msg) -> { if (msg instanceof MyMsgA) { return immutable((ctx2, msg2) -> { if (msg2 instanceof MyMsgB) { @@ -63,9 +63,9 @@ public class ActorCompile { } { - Behavior b = Actor.withTimers(timers -> { + Behavior b = Behaviors.withTimers(timers -> { timers.startPeriodicTimer("key", new MyMsgB("tick"), Duration.create(1, TimeUnit.SECONDS)); - return Actor.ignore(); + return Behaviors.ignore(); }); } @@ -107,8 +107,8 @@ public class ActorCompile { SupervisorStrategy strategy7 = strategy6.withResetBackoffAfter(Duration.create(2, TimeUnit.SECONDS)); Behavior behv = - Actor.supervise( - Actor.supervise(Actor.ignore()).onFailure(IllegalStateException.class, strategy6) + Behaviors.supervise( + Behaviors.supervise(Behaviors.ignore()).onFailure(IllegalStateException.class, strategy6) ).onFailure(RuntimeException.class, strategy1); } diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/AdapterTest.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/AdapterTest.java index 7ae2d64a42..ad18b8e5d9 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/AdapterTest.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/AdapterTest.java @@ -19,7 +19,7 @@ import akka.actor.typed.Signal; import akka.actor.typed.Terminated; import akka.testkit.javadsl.TestKit; import akka.actor.SupervisorStrategy; -import static akka.actor.typed.javadsl.Actor.*; +import static akka.actor.typed.javadsl.Behaviors.*; public class AdapterTest extends JUnitSuite { @@ -187,7 +187,7 @@ public class AdapterTest extends JUnitSuite { } static Behavior typed2() { - return Actor.immutable((ctx, msg) -> { + return Behaviors.immutable((ctx, msg) -> { if (msg instanceof Ping) { ActorRef replyTo = ((Ping) msg).replyTo; replyTo.tell("pong"); diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/BehaviorBuilderTest.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/BehaviorBuilderTest.java index 7c7ad08577..26f0e123f8 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/BehaviorBuilderTest.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/BehaviorBuilderTest.java @@ -12,8 +12,8 @@ import akka.actor.typed.ActorRef; import java.util.ArrayList; -import static akka.actor.typed.javadsl.Actor.same; -import static akka.actor.typed.javadsl.Actor.stopped; +import static akka.actor.typed.javadsl.Behaviors.same; +import static akka.actor.typed.javadsl.Behaviors.stopped; /** * Test creating [[Behavior]]s using [[BehaviorBuilder]] @@ -32,7 +32,7 @@ public class BehaviorBuilderTest extends JUnitSuite { @Test public void shouldCompile() { - Behavior b = Actor.immutable(Message.class) + Behavior b = Behaviors.immutable(Message.class) .onMessage(One.class, (ctx, o) -> { o.foo(); return same(); @@ -40,7 +40,7 @@ public class BehaviorBuilderTest extends JUnitSuite { .onMessage(One.class, o -> o.foo().startsWith("a"), (ctx, o) -> same()) .onMessageUnchecked(MyList.class, (ActorContext ctx, MyList l) -> { String first = l.get(0); - return Actor.same(); + return Behaviors.same(); }) .onSignal(Terminated.class, (ctx, t) -> { System.out.println("Terminating along with " + t.getRef()); @@ -65,7 +65,7 @@ public class BehaviorBuilderTest extends JUnitSuite { } public Behavior immutableCounter(int currentValue) { - return Actor.immutable(CounterMessage.class) + return Behaviors.immutable(CounterMessage.class) .onMessage(Increase.class, (ctx, o) -> { return immutableCounter(currentValue + 1); }) diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ReceiveBuilderTest.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ReceiveBuilderTest.java index 1f47d4932f..70d2fa444c 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ReceiveBuilderTest.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/ReceiveBuilderTest.java @@ -17,7 +17,7 @@ public class ReceiveBuilderTest extends JUnitSuite { @Test public void testMutableCounter() { - Behavior mutable = Actor.mutable(ctx -> new Actor.MutableBehavior() { + Behavior mutable = Behaviors.mutable(ctx -> new Behaviors.MutableBehavior() { int currentValue = 0; private Behavior receiveIncrease(BehaviorBuilderTest.Increase msg) { @@ -31,7 +31,7 @@ public class ReceiveBuilderTest extends JUnitSuite { } @Override - public Actor.Receive createReceive() { + public Behaviors.Receive createReceive() { return receiveBuilder() .onMessage(BehaviorBuilderTest.Increase.class, this::receiveIncrease) .onMessage(BehaviorBuilderTest.Get.class, this::receiveGet) @@ -40,7 +40,7 @@ public class ReceiveBuilderTest extends JUnitSuite { }); } - private static class MyMutableBehavior extends Actor.MutableBehavior { + private static class MyMutableBehavior extends Behaviors.MutableBehavior { private int value; public MyMutableBehavior(int initialValue) { @@ -49,7 +49,7 @@ public class ReceiveBuilderTest extends JUnitSuite { } @Override - public Actor.Receive createReceive() { + public Behaviors.Receive createReceive() { assertEquals(42, value); return receiveBuilder().build(); } @@ -58,6 +58,6 @@ public class ReceiveBuilderTest extends JUnitSuite { @Test public void testInitializationOrder() throws Exception { MyMutableBehavior mutable = new MyMutableBehavior(42); - assertEquals(Actor.unhandled(), mutable.receiveMessage(null, new BehaviorBuilderTest.Increase())); + assertEquals(Behaviors.unhandled(), mutable.receiveMessage(null, new BehaviorBuilderTest.Increase())); } } diff --git a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/WatchTest.java b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/WatchTest.java index 2da0076ae9..23746ddcf2 100644 --- a/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/WatchTest.java +++ b/akka-actor-typed-tests/src/test/java/akka/actor/typed/javadsl/WatchTest.java @@ -14,8 +14,7 @@ import akka.util.Timeout; import org.junit.Test; import akka.actor.typed.*; -import static akka.actor.typed.javadsl.Actor.*; -import static akka.actor.typed.javadsl.AskPattern.*; +import static akka.actor.typed.javadsl.Behaviors.*; public class WatchTest extends JUnitSuite { 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 2d1ba298ce..ccbd8e258b 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 @@ -8,7 +8,7 @@ import akka.actor.typed.ActorRef; import akka.actor.typed.ActorSystem; import akka.actor.typed.Behavior; import akka.actor.typed.Terminated; -import akka.actor.typed.javadsl.Actor; +import akka.actor.typed.javadsl.Behaviors; import akka.actor.typed.javadsl.AskPattern; import akka.util.Timeout; @@ -47,10 +47,10 @@ public class IntroTest { } } - public static final Behavior greeter = Actor.immutable((ctx, msg) -> { + public static final Behavior greeter = Behaviors.immutable((ctx, msg) -> { System.out.println("Hello " + msg.whom + "!"); msg.replyTo.tell(new Greeted(msg.whom)); - return Actor.same(); + return Behaviors.same(); }); } //#hello-world-actor @@ -133,7 +133,7 @@ public class IntroTest { } private static Behavior chatRoom(List> sessions) { - return Actor.immutable(Command.class) + return Behaviors.immutable(Command.class) .onMessage(GetSession.class, (ctx, getSession) -> { ActorRef wrapper = ctx.spawnAdapter(p -> new PostSessionMessage(getSession.screenName, p.message)); @@ -146,7 +146,7 @@ public class IntroTest { .onMessage(PostSessionMessage.class, (ctx, post) -> { MessagePosted mp = new MessagePosted(post.screenName, post.message); sessions.forEach(s -> s.tell(mp)); - return Actor.same(); + return Behaviors.same(); }) .build(); } @@ -161,19 +161,19 @@ public class IntroTest { } public static Behavior behavior() { - return Actor.immutable(ChatRoom.SessionEvent.class) + return Behaviors.immutable(ChatRoom.SessionEvent.class) .onMessage(ChatRoom.SessionDenied.class, (ctx, msg) -> { System.out.println("cannot start chat room session: " + msg.reason); - return Actor.stopped(); + return Behaviors.stopped(); }) .onMessage(ChatRoom.SessionGranted.class, (ctx, msg) -> { msg.handle.tell(new ChatRoom.PostMessage("Hello World!")); - return Actor.same(); + return Behaviors.same(); }) .onMessage(ChatRoom.MessagePosted.class, (ctx, msg) -> { System.out.println("message has been posted by '" + msg.screenName +"': " + msg.message); - return Actor.stopped(); + return Behaviors.stopped(); }) .build(); } @@ -184,7 +184,7 @@ public class IntroTest { public static void runChatRoom() throws Exception { //#chatroom-main - Behavior main = Actor.deferred(ctx -> { + Behavior main = Behaviors.deferred(ctx -> { ActorRef chatRoom = ctx.spawn(ChatRoom.behavior(), "chatRoom"); ActorRef gabbler = @@ -192,8 +192,8 @@ public class IntroTest { ctx.watch(gabbler); chatRoom.tell(new ChatRoom.GetSession("ol’ Gabbler", gabbler)); - return Actor.immutable(Void.class) - .onSignal(Terminated.class, (c, sig) -> Actor.stopped()) + return Behaviors.immutable(Void.class) + .onSignal(Terminated.class, (c, sig) -> Behaviors.stopped()) .build(); }); diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/MutableIntroTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/MutableIntroTest.java index 89ed6a9dc1..8bb6da2e1d 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/MutableIntroTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/MutableIntroTest.java @@ -6,8 +6,8 @@ package jdocs.akka.actor.typed; //#imports import akka.actor.typed.ActorRef; import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.Actor; -import akka.actor.typed.javadsl.Actor.Receive; +import akka.actor.typed.javadsl.Behaviors; +import akka.actor.typed.javadsl.Behaviors.Receive; import akka.actor.typed.javadsl.ActorContext; //#imports import java.util.ArrayList; @@ -72,10 +72,10 @@ public class MutableIntroTest { //#chatroom-behavior public static Behavior behavior() { - return Actor.mutable(ChatRoomBehavior::new); + return Behaviors.mutable(ChatRoomBehavior::new); } - public static class ChatRoomBehavior extends Actor.MutableBehavior { + public static class ChatRoomBehavior extends Behaviors.MutableBehavior { final ActorContext ctx; final List> sessions = new ArrayList>(); @@ -91,7 +91,7 @@ public class MutableIntroTest { new PostSessionMessage(getSession.screenName, p.message)); getSession.replyTo.tell(new SessionGranted(wrapper)); sessions.add(getSession.replyTo); - return Actor.same(); + return Behaviors.same(); }) .onMessage(PostSessionMessage.class, post -> { MessagePosted mp = new MessagePosted(post.screenName, post.message); 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 cea42bc374..67588f2d59 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 @@ -17,8 +17,8 @@ import org.junit.Test; import org.scalatest.junit.JUnitSuite; import scala.concurrent.duration.Duration; -import static akka.actor.typed.javadsl.Actor.same; -import static akka.actor.typed.javadsl.Actor.stopped; +import static akka.actor.typed.javadsl.Behaviors.same; +import static akka.actor.typed.javadsl.Behaviors.stopped; public class TypedWatchingUntypedTest extends JUnitSuite { @@ -36,7 +36,7 @@ public class TypedWatchingUntypedTest extends JUnitSuite { public static class Pong implements Command { } public static Behavior behavior() { - return akka.actor.typed.javadsl.Actor.deferred(context -> { + return akka.actor.typed.javadsl.Behaviors.deferred(context -> { akka.actor.ActorRef second = Adapter.actorOf(context, Untyped.props(), "second"); Adapter.watch(context, second); @@ -44,7 +44,7 @@ public class TypedWatchingUntypedTest extends JUnitSuite { second.tell(new Typed.Ping(context.getSelf().narrow()), Adapter.toUntyped(context.getSelf())); - return akka.actor.typed.javadsl.Actor.immutable(Typed.Command.class) + return akka.actor.typed.javadsl.Behaviors.immutable(Typed.Command.class) .onMessage(Typed.Pong.class, (ctx, msg) -> { Adapter.stop(ctx, second); return same(); diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/UntypedWatchingTypedTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/UntypedWatchingTypedTest.java index 15fb6f9309..591c4f5f69 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/UntypedWatchingTypedTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/UntypedWatchingTypedTest.java @@ -7,7 +7,7 @@ import akka.actor.AbstractActor; import akka.actor.typed.ActorRef; import akka.actor.typed.ActorSystem; import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.Actor; +import akka.actor.typed.javadsl.Behaviors; //#adapter-import // In java use the static methods on Adapter to convert from typed to untyped import akka.actor.typed.javadsl.Adapter; @@ -18,7 +18,7 @@ import org.junit.Test; import org.scalatest.junit.JUnitSuite; import scala.concurrent.duration.Duration; -import static akka.actor.typed.javadsl.Actor.same; +import static akka.actor.typed.javadsl.Behaviors.same; public class UntypedWatchingTypedTest extends JUnitSuite { @@ -66,7 +66,7 @@ public class UntypedWatchingTypedTest extends JUnitSuite { public static class Pong { } public static Behavior behavior() { - return Actor.immutable(Typed.Command.class) + return Behaviors.immutable(Typed.Command.class) .onMessage(Typed.Ping.class, (ctx, msg) -> { msg.replyTo.tell(new Pong()); return same(); diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/async/BasicAsyncTestingTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/async/BasicAsyncTestingTest.java index 7177c1ac05..a17eb56050 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/async/BasicAsyncTestingTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/async/BasicAsyncTestingTest.java @@ -5,7 +5,7 @@ package jdocs.akka.typed.testing.async; import akka.actor.typed.ActorRef; import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.Actor; +import akka.actor.typed.javadsl.Behaviors; import akka.testkit.typed.javadsl.TestProbe; import akka.testkit.typed.TestKit; import org.junit.AfterClass; @@ -33,9 +33,9 @@ public class BasicAsyncTestingTest extends TestKit { } } - Behavior echoActor = Actor.immutable((ctx, ping) -> { + Behavior echoActor = Behaviors.immutable((ctx, ping) -> { ping.replyTo.tell(new Pong(ping.msg)); - return Actor.same(); + return Behaviors.same(); }); //#under-test diff --git a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/sync/BasicSyncTestingTest.java b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/sync/BasicSyncTestingTest.java index 8917b6f1fd..56eeabacc6 100644 --- a/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/sync/BasicSyncTestingTest.java +++ b/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/testing/sync/BasicSyncTestingTest.java @@ -11,7 +11,7 @@ import org.scalatest.junit.JUnitSuite; public class BasicSyncTestingTest extends JUnitSuite { //#child - public static Behavior childActor = Actor.immutable((ctx, msg) -> Actor.same()); + public static Behavior childActor = Behaviors.immutable((ctx, msg) -> Behaviors.same()); //#child //#under-test @@ -38,27 +38,27 @@ public class BasicSyncTestingTest extends JUnitSuite { } } - public static Behavior myBehaviour = Actor.immutable(Command.class) + public static Behavior myBehaviour = Behaviors.immutable(Command.class) .onMessage(CreateAChild.class, (ctx, msg) -> { ctx.spawn(childActor, msg.childName); - return Actor.same(); + return Behaviors.same(); }) .onMessage(CreateAnAnonymousChild.class, (ctx, msg) -> { ctx.spawnAnonymous(childActor); - return Actor.same(); + return Behaviors.same(); }) .onMessage(SayHelloToChild.class, (ctx, msg) -> { ActorRef child = ctx.spawn(childActor, msg.childName); child.tell("hello"); - return Actor.same(); + return Behaviors.same(); }) .onMessage(SayHelloToAnonymousChild.class, (ctx, msg) -> { ActorRef child = ctx.spawnAnonymous(childActor); child.tell("hello stranger"); - return Actor.same(); + return Behaviors.same(); }).onMessage(SayHello.class, (ctx, msg) -> { msg.who.tell("hello"); - return Actor.same(); + return Behaviors.same(); }).build(); //#under-test 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 fd5759c219..e72a987526 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 @@ -3,8 +3,8 @@ */ package akka.actor.typed -import akka.actor.typed.scaladsl.Actor._ -import akka.actor.typed.scaladsl.{ Actor, AskPattern } +import akka.actor.typed.scaladsl.Behaviors._ +import akka.actor.typed.scaladsl.{ Behaviors, AskPattern } import akka.actor.{ ActorInitializationException, DeadLetterSuppression, InvalidMessageException } import akka.testkit.AkkaSpec import akka.testkit.TestEvent.Mute @@ -84,18 +84,18 @@ object ActorContextSpec { final case class Adapter(a: ActorRef[Command]) extends Event def subject(monitor: ActorRef[Monitor], ignorePostStop: Boolean): Behavior[Command] = - Actor.immutable[Command] { + Behaviors.immutable[Command] { (ctx, message) ⇒ message match { case ReceiveTimeout ⇒ monitor ! GotReceiveTimeout - Actor.same + Behaviors.same case Ping(replyTo) ⇒ replyTo ! Pong1 - Actor.same + Behaviors.same case Miss(replyTo) ⇒ replyTo ! Missed - Actor.unhandled + Behaviors.unhandled case Renew(replyTo) ⇒ replyTo ! Renewed subject(monitor, ignorePostStop) @@ -103,87 +103,87 @@ object ActorContextSpec { throw ex case MkChild(name, mon, replyTo) ⇒ val child = name match { - case None ⇒ ctx.spawnAnonymous(Actor.supervise(subject(mon, ignorePostStop)).onFailure(SupervisorStrategy.restart)) - case Some(n) ⇒ ctx.spawn(Actor.supervise(subject(mon, ignorePostStop)).onFailure(SupervisorStrategy.restart), n) + case None ⇒ ctx.spawnAnonymous(Behaviors.supervise(subject(mon, ignorePostStop)).onFailure(SupervisorStrategy.restart)) + case Some(n) ⇒ ctx.spawn(Behaviors.supervise(subject(mon, ignorePostStop)).onFailure(SupervisorStrategy.restart), n) } replyTo ! Created(child) - Actor.same + Behaviors.same case SetTimeout(d, replyTo) ⇒ d match { case f: FiniteDuration ⇒ ctx.setReceiveTimeout(f, ReceiveTimeout) case _ ⇒ ctx.cancelReceiveTimeout() } replyTo ! TimeoutSet - Actor.same + Behaviors.same case Schedule(delay, target, msg, replyTo) ⇒ replyTo ! Scheduled ctx.schedule(delay, target, msg) - Actor.same + Behaviors.same case Stop ⇒ - Actor.stopped + Behaviors.stopped case Kill(ref, replyTo) ⇒ if (ctx.stop(ref)) replyTo ! Killed else replyTo ! NotKilled - Actor.same + Behaviors.same case Watch(ref, replyTo) ⇒ ctx.watch(ref) replyTo ! Watched - Actor.same + Behaviors.same case Unwatch(ref, replyTo) ⇒ ctx.unwatch(ref) replyTo ! Unwatched - Actor.same + Behaviors.same case GetInfo(replyTo) ⇒ replyTo ! Info(ctx.self, ctx.system) - Actor.same + Behaviors.same case GetChild(name, replyTo) ⇒ replyTo ! Child(ctx.child(name)) - Actor.same + Behaviors.same case GetChildren(replyTo) ⇒ replyTo ! Children(ctx.children.toSet) - Actor.same + Behaviors.same case BecomeInert(replyTo) ⇒ replyTo ! BecameInert - Actor.immutable { + Behaviors.immutable { case (_, Ping(replyTo)) ⇒ replyTo ! Pong2 - Actor.same + Behaviors.same case (_, Throw(ex)) ⇒ throw ex - case _ ⇒ Actor.unhandled + case _ ⇒ Behaviors.unhandled } case BecomeCareless(replyTo) ⇒ replyTo ! BecameCareless - Actor.immutable[Command] { - case (_, _) ⇒ Actor.unhandled + Behaviors.immutable[Command] { + case (_, _) ⇒ Behaviors.unhandled } onSignal { - case (_, PostStop) if ignorePostStop ⇒ Actor.same // ignore PostStop here - case (_, Terminated(_)) ⇒ Actor.unhandled + case (_, PostStop) if ignorePostStop ⇒ Behaviors.same // ignore PostStop here + case (_, Terminated(_)) ⇒ Behaviors.unhandled case (_, sig) ⇒ monitor ! GotSignal(sig) - Actor.same + Behaviors.same } case GetAdapter(replyTo, name) ⇒ replyTo ! Adapter(ctx.spawnAdapter(identity, name)) - Actor.same + Behaviors.same } } onSignal { - case (_, PostStop) if ignorePostStop ⇒ Actor.same // ignore PostStop here - case (ctx, signal) ⇒ monitor ! GotSignal(signal); Actor.same + case (_, PostStop) if ignorePostStop ⇒ Behaviors.same // ignore PostStop here + case (ctx, signal) ⇒ monitor ! GotSignal(signal); Behaviors.same } def oldSubject(monitor: ActorRef[Monitor], ignorePostStop: Boolean): Behavior[Command] = { - Actor.immutable[Command] { + Behaviors.immutable[Command] { case (ctx, message) ⇒ message match { case ReceiveTimeout ⇒ monitor ! GotReceiveTimeout - Actor.same + Behaviors.same case Ping(replyTo) ⇒ replyTo ! Pong1 - Actor.same + Behaviors.same case Miss(replyTo) ⇒ replyTo ! Missed - Actor.unhandled + Behaviors.unhandled case Renew(replyTo) ⇒ replyTo ! Renewed subject(monitor, ignorePostStop) @@ -191,75 +191,75 @@ object ActorContextSpec { throw ex case MkChild(name, mon, replyTo) ⇒ val child = name match { - case None ⇒ ctx.spawnAnonymous(Actor.supervise(subject(mon, ignorePostStop)).onFailure[Throwable](SupervisorStrategy.restart)) - case Some(n) ⇒ ctx.spawn(Actor.supervise(subject(mon, ignorePostStop)).onFailure[Throwable](SupervisorStrategy.restart), n) + case None ⇒ ctx.spawnAnonymous(Behaviors.supervise(subject(mon, ignorePostStop)).onFailure[Throwable](SupervisorStrategy.restart)) + case Some(n) ⇒ ctx.spawn(Behaviors.supervise(subject(mon, ignorePostStop)).onFailure[Throwable](SupervisorStrategy.restart), n) } replyTo ! Created(child) - Actor.same + Behaviors.same case SetTimeout(d, replyTo) ⇒ d match { case f: FiniteDuration ⇒ ctx.setReceiveTimeout(f, ReceiveTimeout) case _ ⇒ ctx.cancelReceiveTimeout() } replyTo ! TimeoutSet - Actor.same + Behaviors.same case Schedule(delay, target, msg, replyTo) ⇒ replyTo ! Scheduled ctx.schedule(delay, target, msg) - Actor.same + Behaviors.same case Stop ⇒ - Actor.stopped + Behaviors.stopped case Kill(ref, replyTo) ⇒ if (ctx.stop(ref)) replyTo ! Killed else replyTo ! NotKilled - Actor.same + Behaviors.same case Watch(ref, replyTo) ⇒ ctx.watch(ref) replyTo ! Watched - Actor.same + Behaviors.same case Unwatch(ref, replyTo) ⇒ ctx.unwatch(ref) replyTo ! Unwatched - Actor.same + Behaviors.same case GetInfo(replyTo) ⇒ replyTo ! Info(ctx.self, ctx.system) - Actor.same + Behaviors.same case GetChild(name, replyTo) ⇒ replyTo ! Child(ctx.child(name)) - Actor.same + Behaviors.same case GetChildren(replyTo) ⇒ replyTo ! Children(ctx.children.toSet) - Actor.same + Behaviors.same case BecomeInert(replyTo) ⇒ replyTo ! BecameInert - Actor.immutable[Command] { + Behaviors.immutable[Command] { case (_, Ping(r)) ⇒ r ! Pong2 - Actor.same + Behaviors.same case (_, Throw(ex)) ⇒ throw ex - case _ ⇒ Actor.same + case _ ⇒ Behaviors.same } case BecomeCareless(replyTo) ⇒ replyTo ! BecameCareless - Actor.immutable[Command] { - case _ ⇒ Actor.unhandled + Behaviors.immutable[Command] { + case _ ⇒ Behaviors.unhandled } onSignal { - case (_, PostStop) if ignorePostStop ⇒ Actor.same // ignore PostStop here - case (_, Terminated(_)) ⇒ Actor.unhandled + case (_, PostStop) if ignorePostStop ⇒ Behaviors.same // ignore PostStop here + case (_, Terminated(_)) ⇒ Behaviors.unhandled case (_, sig) ⇒ monitor ! GotSignal(sig) - Actor.same + Behaviors.same } case GetAdapter(replyTo, name) ⇒ replyTo ! Adapter(ctx.spawnAdapter(identity, name)) - Actor.same + Behaviors.same } } onSignal { - case (_, PostStop) if ignorePostStop ⇒ Actor.same // ignore PostStop here + case (_, PostStop) if ignorePostStop ⇒ Behaviors.same // ignore PostStop here case (_, signal) ⇒ monitor ! GotSignal(signal) - Actor.same + Behaviors.same } } @@ -279,7 +279,7 @@ object ActorContextSpec { class SimulatedException(message: String) extends RuntimeException(message) with NoStackTrace def guardian(outstanding: Map[ActorRef[_], ActorRef[Status]] = Map.empty): Behavior[GuardianCommand] = - Actor.immutable[GuardianCommand] { + Behaviors.immutable[GuardianCommand] { case (ctx, r: RunTest[t]) ⇒ val test = ctx.spawn(r.behavior, r.name) ctx.schedule(r.timeout, r.replyTo, Timedout) @@ -477,7 +477,7 @@ abstract class ActorContextSpec extends TypedAkkaSpec { } "correctly wire the lifecycle hooks" in { - sync(setup("ctx01", Some(b ⇒ Actor.supervise(b).onFailure[Throwable](SupervisorStrategy.restart)), ignorePostStop = false) { (ctx, startWith) ⇒ + sync(setup("ctx01", Some(b ⇒ Behaviors.supervise(b).onFailure[Throwable](SupervisorStrategy.restart)), ignorePostStop = false) { (ctx, startWith) ⇒ val self = ctx.self val ex = new Exception("KABOOM1") startWith { subj ⇒ @@ -555,7 +555,7 @@ abstract class ActorContextSpec extends TypedAkkaSpec { } "reset behavior upon Restart" in { - sync(setup("ctx05", Some(Actor.supervise(_).onFailure(SupervisorStrategy.restart))) { (ctx, startWith) ⇒ + sync(setup("ctx05", Some(Behaviors.supervise(_).onFailure(SupervisorStrategy.restart))) { (ctx, startWith) ⇒ val self = ctx.self val ex = new Exception("KABOOM05") startWith @@ -572,7 +572,7 @@ abstract class ActorContextSpec extends TypedAkkaSpec { "not reset behavior upon Resume" in { sync(setup( "ctx06", - Some(b ⇒ Actor.supervise(b).onFailure(SupervisorStrategy.resume))) { (ctx, startWith) ⇒ + Some(b ⇒ Behaviors.supervise(b).onFailure(SupervisorStrategy.resume))) { (ctx, startWith) ⇒ val self = ctx.self val ex = new Exception("KABOOM06") startWith @@ -802,7 +802,7 @@ class NormalActorContextSpec extends ActorContextSpec { class WidenedActorContextSpec extends ActorContextSpec { - import Actor._ + import Behaviors._ override def suite = "widened" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = @@ -812,17 +812,17 @@ class WidenedActorContextSpec extends ActorContextSpec { class DeferredActorContextSpec extends ActorContextSpec { override def suite = "deferred" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = - Actor.deferred(_ ⇒ subject(ctx.self, ignorePostStop)) + Behaviors.deferred(_ ⇒ subject(ctx.self, ignorePostStop)) } class NestedDeferredActorContextSpec extends ActorContextSpec { override def suite = "nexted-deferred" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = - Actor.deferred(_ ⇒ Actor.deferred(_ ⇒ subject(ctx.self, ignorePostStop))) + Behaviors.deferred(_ ⇒ Behaviors.deferred(_ ⇒ subject(ctx.self, ignorePostStop))) } class TapActorContextSpec extends ActorContextSpec { override def suite = "tap" override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] = - Actor.tap((_, _) ⇒ (), (_, _) ⇒ (), subject(ctx.self, ignorePostStop)) + Behaviors.tap((_, _) ⇒ (), (_, _) ⇒ (), subject(ctx.self, ignorePostStop)) } diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/AskSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/AskSpec.scala index b40173860e..4462bd04dd 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/AskSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/AskSpec.scala @@ -4,8 +4,8 @@ package akka.actor.typed import akka.actor.typed.internal.adapter.ActorSystemAdapter -import akka.actor.typed.scaladsl.Actor -import akka.actor.typed.scaladsl.Actor._ +import akka.actor.typed.scaladsl.Behaviors +import akka.actor.typed.scaladsl.Behaviors._ import akka.actor.typed.scaladsl.AskPattern._ import akka.pattern.AskTimeoutException import akka.testkit.typed.TestKit @@ -29,10 +29,10 @@ class AskSpec extends TestKit("AskSpec") with TypedAkkaSpec with ScalaFutures { val behavior: Behavior[Msg] = immutable[Msg] { case (_, foo: Foo) ⇒ foo.replyTo ! "foo" - Actor.same + Behaviors.same case (_, Stop(r)) ⇒ r ! () - Actor.stopped + Behaviors.stopped } "Ask pattern" must { 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 4d1019eb08..fc33eff3a6 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 @@ -3,8 +3,8 @@ */ package akka.actor.typed -import akka.actor.typed.scaladsl.{ Actor ⇒ SActor } -import akka.actor.typed.javadsl.{ Actor ⇒ JActor, ActorContext ⇒ JActorContext } +import akka.actor.typed.scaladsl.{ Behaviors ⇒ SActor } +import akka.actor.typed.javadsl.{ Behaviors ⇒ JActor, ActorContext ⇒ JActorContext } import akka.japi.function.{ Function ⇒ F1e, Function2 ⇒ F2, Procedure2 ⇒ P2 } import akka.japi.pf.{ FI, PFBuilder } import java.util.function.{ Function ⇒ F1 } 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 95b5a9ec79..de2b150cc1 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 @@ -5,8 +5,8 @@ package akka.actor.typed import scala.concurrent.duration._ import scala.util.control.NoStackTrace -import akka.actor.typed.scaladsl.Actor -import akka.actor.typed.scaladsl.Actor.BehaviorDecorators +import akka.actor.typed.scaladsl.Behaviors +import akka.actor.typed.scaladsl.Behaviors.BehaviorDecorators import akka.testkit.typed.{ BehaviorTestkit, TestInbox, TestKit, TestKitSettings } import akka.testkit.typed.scaladsl._ @@ -19,10 +19,10 @@ object DeferredSpec { case object Started extends Event def target(monitor: ActorRef[Event]): Behavior[Command] = - Actor.immutable((_, cmd) ⇒ cmd match { + Behaviors.immutable((_, cmd) ⇒ cmd match { case Ping ⇒ monitor ! Pong - Actor.same + Behaviors.same }) } @@ -34,7 +34,7 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "Deferred behaviour" must { "must create underlying" in { val probe = TestProbe[Event]("evt") - val behv = Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[Command] { _ ⇒ probe.ref ! Started target(probe.ref) } @@ -46,16 +46,16 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must stop when exception from factory" in { val probe = TestProbe[Event]("evt") - val behv = Actor.deferred[Command] { ctx ⇒ - val child = ctx.spawnAnonymous(Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[Command] { ctx ⇒ + val child = ctx.spawnAnonymous(Behaviors.deferred[Command] { _ ⇒ probe.ref ! Started throw new RuntimeException("simulated exc from factory") with NoStackTrace }) ctx.watch(child) - Actor.immutable[Command]((_, _) ⇒ Actor.same).onSignal { + Behaviors.immutable[Command]((_, _) ⇒ Behaviors.same).onSignal { case (_, Terminated(`child`)) ⇒ probe.ref ! Pong - Actor.stopped + Behaviors.stopped } } spawn(behv) @@ -65,13 +65,13 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must stop when deferred result it Stopped" in { val probe = TestProbe[Event]("evt") - val behv = Actor.deferred[Command] { ctx ⇒ - val child = ctx.spawnAnonymous(Actor.deferred[Command](_ ⇒ Actor.stopped)) + val behv = Behaviors.deferred[Command] { ctx ⇒ + val child = ctx.spawnAnonymous(Behaviors.deferred[Command](_ ⇒ Behaviors.stopped)) ctx.watch(child) - Actor.immutable[Command]((_, _) ⇒ Actor.same).onSignal { + Behaviors.immutable[Command]((_, _) ⇒ Behaviors.same).onSignal { case (_, Terminated(`child`)) ⇒ probe.ref ! Pong - Actor.stopped + Behaviors.stopped } } spawn(behv) @@ -80,8 +80,8 @@ class DeferredSpec extends TestKit with TypedAkkaSpec { "must create underlying when nested" in { val probe = TestProbe[Event]("evt") - val behv = Actor.deferred[Command] { _ ⇒ - Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[Command] { _ ⇒ + Behaviors.deferred[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 = Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[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 = Actor.monitor(monitorProbe.ref, Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.monitor(monitorProbe.ref, Behaviors.deferred[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 = Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[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 = Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.deferred[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 0545a97bb9..8fdea9ea19 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 @@ -6,7 +6,7 @@ package akka.actor.typed import scala.concurrent.duration.FiniteDuration import java.util.concurrent.TimeoutException -import akka.actor.typed.scaladsl.Actor._ +import akka.actor.typed.scaladsl.Behaviors._ import scala.concurrent.duration.Deadline 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 0cf84bdb79..3706ef08e6 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 @@ -3,10 +3,10 @@ */ package akka.actor.typed -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import scala.concurrent.duration._ -import akka.actor.typed.scaladsl.Actor._ +import akka.actor.typed.scaladsl.Behaviors._ import akka.testkit.typed.{ BehaviorTestkit, TestInbox, TestKit, TestKitSettings } import scala.util.control.NoStackTrace @@ -37,23 +37,23 @@ object SupervisionSpec { cmd match { case Ping ⇒ monitor ! Pong - Actor.same + Behaviors.same case IncrementState ⇒ targetBehavior(monitor, state.copy(n = state.n + 1)) case GetState ⇒ val reply = state.copy(children = ctx.children.map(c ⇒ c.path.name → c.upcast[Command]).toMap) monitor ! reply - Actor.same + Behaviors.same case CreateChild(childBehv, childName) ⇒ ctx.spawn(childBehv, childName) - Actor.same + Behaviors.same case Throw(e) ⇒ throw e } } onSignal { case (_, sig) ⇒ monitor ! GotSignal(sig) - Actor.same + Behaviors.same } class FailingConstructor(monitor: ActorRef[Event]) extends MutableBehavior[Command] { @@ -62,7 +62,7 @@ object SupervisionSpec { override def onMessage(msg: Command): Behavior[Command] = { monitor ! Pong - Actor.same + Behaviors.same } } } @@ -163,7 +163,7 @@ class StubbedSupervisionSpec extends WordSpec with Matchers { "not catch fatal error" in { val inbox = TestInbox[Event]() - val behv = Actor.supervise(targetBehavior(inbox.ref)) + val behv = Behaviors.supervise(targetBehavior(inbox.ref)) .onFailure[Throwable](SupervisorStrategy.restart) val testkit = BehaviorTestkit(behv) intercept[StackOverflowError] { @@ -245,7 +245,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS "A supervised actor" must { "receive message" in { val probe = TestProbe[Event]("evt") - val behv = Actor.supervise(targetBehavior(probe.ref)) + val behv = Behaviors.supervise(targetBehavior(probe.ref)) .onFailure[Throwable](SupervisorStrategy.restart) val ref = spawn(behv) ref ! Ping @@ -263,7 +263,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS "stop when unhandled exception" in { val probe = TestProbe[Event]("evt") - val behv = Actor.supervise(targetBehavior(probe.ref)) + val behv = Behaviors.supervise(targetBehavior(probe.ref)) .onFailure[Exc1](SupervisorStrategy.restart) val ref = spawn(behv) ref ! Throw(new Exc3) @@ -272,7 +272,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS "restart when handled exception" in { val probe = TestProbe[Event]("evt") - val behv = Actor.supervise(targetBehavior(probe.ref)) + val behv = Behaviors.supervise(targetBehavior(probe.ref)) .onFailure[Exc1](SupervisorStrategy.restart) val ref = spawn(behv) ref ! IncrementState @@ -287,7 +287,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS "NOT stop children when restarting" in { val parentProbe = TestProbe[Event]("evt") - val behv = Actor.supervise(targetBehavior(parentProbe.ref)) + val behv = Behaviors.supervise(targetBehavior(parentProbe.ref)) .onFailure[Exc1](SupervisorStrategy.restart) val ref = spawn(behv) @@ -321,8 +321,8 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS "support nesting to handle different exceptions" in { val probe = TestProbe[Event]("evt") - val behv = Actor.supervise( - Actor.supervise(targetBehavior(probe.ref)) + val behv = Behaviors.supervise( + Behaviors.supervise(targetBehavior(probe.ref)) .onFailure[Exc2](SupervisorStrategy.resume) ).onFailure[Exc3](SupervisorStrategy.restart) val ref = spawn(behv) @@ -354,7 +354,7 @@ class SupervisionSpec extends TestKit("SupervisionSpec") with TypedAkkaSpecWithS val strategy = SupervisorStrategy .restartWithBackoff(minBackoff, 10.seconds, 0.0) .withResetBackoffAfter(10.seconds) - val behv = Actor.supervise(Actor.deferred[Command] { _ ⇒ + val behv = Behaviors.supervise(Behaviors.deferred[Command] { _ ⇒ startedProbe.ref ! Started targetBehavior(probe.ref) }).onFailure[Exception](strategy) diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/TimerSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/TimerSpec.scala index 67f47583e5..5bef67be34 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/TimerSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/TimerSpec.scala @@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger import scala.concurrent.duration._ import scala.util.control.NoStackTrace -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.TimerScheduler import akka.testkit.typed.TestKitSettings import akka.testkit.typed.TestKit @@ -46,21 +46,21 @@ class TimerSpec extends TestKit("TimerSpec") target(monitor, timer, nextCount) } - Actor.immutable[Command] { (ctx, cmd) ⇒ + Behaviors.immutable[Command] { (ctx, cmd) ⇒ cmd match { case Tick(n) ⇒ monitor ! Tock(n) - Actor.same + Behaviors.same case Bump ⇒ bump() case SlowThenBump(latch) ⇒ latch.await(10, TimeUnit.SECONDS) bump() case End ⇒ - Actor.stopped + Behaviors.stopped case Cancel ⇒ timer.cancel("T") - Actor.same + Behaviors.same case Throw(e) ⇒ throw e case SlowThenThrow(latch, e) ⇒ @@ -70,17 +70,17 @@ class TimerSpec extends TestKit("TimerSpec") } onSignal { case (ctx, PreRestart) ⇒ monitor ! GotPreRestart(timer.isTimerActive("T")) - Actor.same + Behaviors.same case (ctx, PostStop) ⇒ monitor ! GotPostStop(timer.isTimerActive("T")) - Actor.same + Behaviors.same } } "A timer" must { "schedule non-repeated ticks" in { val probe = TestProbe[Event]("evt") - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startSingleTimer("T", Tick(1), 10.millis) target(probe.ref, timer, 1) } @@ -95,7 +95,7 @@ class TimerSpec extends TestKit("TimerSpec") "schedule repeated ticks" in { val probe = TestProbe[Event]("evt") - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) } @@ -113,7 +113,7 @@ class TimerSpec extends TestKit("TimerSpec") "replace timer" in { val probe = TestProbe[Event]("evt") - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) } @@ -133,7 +133,7 @@ class TimerSpec extends TestKit("TimerSpec") "cancel timer" in { val probe = TestProbe[Event]("evt") - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) } @@ -150,7 +150,7 @@ class TimerSpec extends TestKit("TimerSpec") "discard timers from old incarnation after restart, alt 1" in { val probe = TestProbe[Event]("evt") val startCounter = new AtomicInteger(0) - val behv = Actor.supervise(Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.supervise(Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(startCounter.incrementAndGet()), interval) target(probe.ref, timer, 1) }).onFailure[Exception](SupervisorStrategy.restart) @@ -173,7 +173,7 @@ class TimerSpec extends TestKit("TimerSpec") "discard timers from old incarnation after restart, alt 2" in { val probe = TestProbe[Event]("evt") - val behv = Actor.supervise(Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.supervise(Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) }).onFailure[Exception](SupervisorStrategy.restart) @@ -199,7 +199,7 @@ class TimerSpec extends TestKit("TimerSpec") "cancel timers when stopped from exception" in { val probe = TestProbe[Event]() - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) } @@ -210,7 +210,7 @@ class TimerSpec extends TestKit("TimerSpec") "cancel timers when stopped voluntarily" in { val probe = TestProbe[Event]() - val behv = Actor.withTimers[Command] { timer ⇒ + val behv = Behaviors.withTimers[Command] { timer ⇒ timer.startPeriodicTimer("T", Tick(1), interval) target(probe.ref, timer, 1) } 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 258e6cfac0..efd7808023 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 @@ -3,7 +3,7 @@ */ package akka.actor.typed -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import scala.concurrent._ import akka.testkit.typed.TestKit @@ -12,8 +12,8 @@ object WatchSpec { case object Stop val terminatorBehavior = - Actor.immutable[Stop.type] { - case (_, Stop) ⇒ Actor.stopped + Behaviors.immutable[Stop.type] { + case (_, Stop) ⇒ Behaviors.stopped } sealed trait Message @@ -32,14 +32,14 @@ class WatchSpec extends TestKit("WordSpec") val terminator = systemActor(terminatorBehavior) val receivedTerminationSignal: Promise[ActorRef[Nothing]] = Promise() - val watcher = systemActor(Actor.immutable[StartWatching] { + val watcher = systemActor(Behaviors.immutable[StartWatching] { case (ctx, StartWatching(watchee)) ⇒ ctx.watch(watchee) - Actor.same + Behaviors.same }.onSignal { case (_, Terminated(stopped)) ⇒ receivedTerminationSignal.success(stopped) - Actor.stopped + Behaviors.stopped }) watcher ! StartWatching(terminator) @@ -52,13 +52,13 @@ class WatchSpec extends TestKit("WordSpec") val terminator = systemActor(terminatorBehavior) val receivedTerminationSignal: Promise[Message] = Promise() - val watcher = systemActor(Actor.immutable[Message] { + val watcher = systemActor(Behaviors.immutable[Message] { case (ctx, StartWatchingWith(watchee, msg)) ⇒ ctx.watchWith(watchee, msg) - Actor.same + Behaviors.same case (_, msg) ⇒ receivedTerminationSignal.success(msg) - Actor.stopped + Behaviors.stopped }) watcher ! StartWatchingWith(terminator, CustomTerminationMessage) diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/ActorSystemSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/ActorSystemSpec.scala index 8df1eabf41..6e1602b435 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/ActorSystemSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/ActorSystemSpec.scala @@ -5,7 +5,7 @@ package akka.actor.typed package internal import akka.actor.InvalidMessageException -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.testkit.typed.TestInbox import org.scalatest._ import org.scalatest.concurrent.{ Eventually, ScalaFutures } @@ -39,7 +39,7 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll "start the guardian actor and terminate when it terminates" in { val t = withSystem( "a", - Actor.immutable[Probe] { case (_, p) ⇒ p.replyTo ! p.msg; Actor.stopped }, doTerminate = false) { sys ⇒ + Behaviors.immutable[Probe] { case (_, p) ⇒ p.replyTo ! p.msg; Behaviors.stopped }, doTerminate = false) { sys ⇒ val inbox = TestInbox[String]("a") sys ! Probe("hello", inbox.ref) eventually { @@ -55,7 +55,7 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll // see issue #24172 "shutdown if guardian shuts down immediately" in { pending - withSystem("shutdown", Actor.stopped[String], doTerminate = false) { sys: ActorSystem[String] ⇒ + withSystem("shutdown", Behaviors.stopped[String], doTerminate = false) { sys: ActorSystem[String] ⇒ sys.whenTerminated.futureValue } } @@ -63,12 +63,12 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll "terminate the guardian actor" in { val inbox = TestInbox[String]("terminate") val sys = system( - Actor.immutable[Probe] { - case (_, _) ⇒ Actor.unhandled + Behaviors.immutable[Probe] { + case (_, _) ⇒ Behaviors.unhandled } onSignal { case (_, PostStop) ⇒ inbox.ref ! "done" - Actor.same + Behaviors.same }, "terminate") sys.terminate().futureValue @@ -80,13 +80,13 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll } "have a name" in { - withSystem("name", Actor.empty[String]) { sys ⇒ + withSystem("name", Behaviors.empty[String]) { sys ⇒ sys.name should ===(suite + "-name") } } "report its uptime" in { - withSystem("uptime", Actor.empty[String]) { sys ⇒ + withSystem("uptime", Behaviors.empty[String]) { sys ⇒ sys.uptime should be < 1L Thread.sleep(1000) sys.uptime should be >= 1L @@ -94,7 +94,7 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll } "have a working thread factory" in { - withSystem("thread", Actor.empty[String]) { sys ⇒ + withSystem("thread", Behaviors.empty[String]) { sys ⇒ val p = Promise[Int] sys.threadFactory.newThread(new Runnable { def run(): Unit = p.success(42) @@ -104,14 +104,14 @@ class ActorSystemSpec extends WordSpec with Matchers with BeforeAndAfterAll } "be able to run Futures" in { - withSystem("futures", Actor.empty[String]) { sys ⇒ + withSystem("futures", Behaviors.empty[String]) { sys ⇒ val f = Future(42)(sys.executionContext) f.futureValue should ===(42) } } "not allow null messages" in { - withSystem("null-messages", Actor.empty[String]) { sys ⇒ + withSystem("null-messages", Behaviors.empty[String]) { sys ⇒ intercept[InvalidMessageException] { sys ! null } diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/MiscMessageSerializerSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/MiscMessageSerializerSpec.scala index a62dbb2719..2ed49570ba 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/MiscMessageSerializerSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/internal/MiscMessageSerializerSpec.scala @@ -4,7 +4,7 @@ package akka.actor.typed.internal import akka.actor.typed.TypedAkkaSpecWithShutdown -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.serialization.SerializationExtension import akka.testkit.typed.TestKit @@ -39,7 +39,7 @@ class MiscMessageSerializerSpec extends TestKit(MiscMessageSerializerSpec.config } "must serialize and deserialize typed actor refs" in { - val ref = spawn(Actor.empty[Unit]) + val ref = spawn(Behaviors.empty[Unit]) checkSerialization(ref) } } diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/receptionist/LocalReceptionistSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/receptionist/LocalReceptionistSpec.scala index 01e8d5a72c..b36366122a 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/receptionist/LocalReceptionistSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/receptionist/LocalReceptionistSpec.scala @@ -5,7 +5,7 @@ package akka.actor.typed.receptionist import akka.actor.typed._ import akka.actor.typed.receptionist.Receptionist._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.AskPattern._ import akka.testkit.typed.{ BehaviorTestkit, TestInbox, TestKit, TestKitSettings } import akka.testkit.typed.scaladsl.TestProbe @@ -17,14 +17,14 @@ class LocalReceptionistSpec extends TestKit with TypedAkkaSpecWithShutdown with trait ServiceA val ServiceKeyA = ServiceKey[ServiceA]("service-a") - val behaviorA = Actor.empty[ServiceA] + val behaviorA = Behaviors.empty[ServiceA] trait ServiceB val ServiceKeyB = ServiceKey[ServiceB]("service-b") - val behaviorB = Actor.empty[ServiceB] + val behaviorB = Behaviors.empty[ServiceB] case object Stop extends ServiceA with ServiceB - val stoppableBehavior = Actor.immutable[Any] { (_, msg) ⇒ + val stoppableBehavior = Behaviors.immutable[Any] { (_, msg) ⇒ msg match { case Stop ⇒ Behavior.stopped case _ ⇒ Behavior.same diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ImmutablePartialSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ImmutablePartialSpec.scala index 7b452fe3d5..11e6e229ca 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ImmutablePartialSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ImmutablePartialSpec.scala @@ -16,10 +16,10 @@ class ImmutablePartialSpec extends TestKit with TypedAkkaSpecWithShutdown { "correctly install the message handler" in { val probe = TestProbe[Command]("probe") val behavior = - Actor.immutablePartial[Command] { + Behaviors.immutablePartial[Command] { case (_, Command2) ⇒ probe.ref ! Command2 - Actor.same + Behaviors.same } val testkit = BehaviorTestkit(behavior) 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 a60ee8c693..d165f841eb 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,13 +14,13 @@ final class OnSignalSpec extends TestKit with TypedAkkaSpecWithShutdown { "must correctly install the signal handler" in { val probe = TestProbe[Done]("probe") val behavior = - Actor.deferred[Nothing] { context ⇒ - val stoppedChild = context.spawn(Actor.stopped, "stopped-child") + Behaviors.deferred[Nothing] { context ⇒ + val stoppedChild = context.spawn(Behaviors.stopped, "stopped-child") context.watch(stoppedChild) - Actor.onSignal[Nothing] { + Behaviors.onSignal[Nothing] { case (_, Terminated(`stoppedChild`)) ⇒ probe.ref ! Done - Actor.stopped + Behaviors.stopped } } spawn[Nothing](behavior) 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 acac897e61..2fbe77da4f 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 @@ -9,7 +9,7 @@ import akka.actor.typed.ActorRef import akka.actor.{ InvalidMessageException, Props } import akka.actor.typed.Behavior import akka.actor.typed.Terminated -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.{ actor ⇒ untyped } import akka.testkit._ import akka.actor.typed.Behavior.UntypedBehavior @@ -33,39 +33,39 @@ object AdapterSpec { } def typed1(ref: untyped.ActorRef, probe: ActorRef[String]): Behavior[String] = - Actor.immutable[String] { + Behaviors.immutable[String] { (ctx, msg) ⇒ msg match { case "send" ⇒ val replyTo = ctx.self.toUntyped ref.tell("ping", replyTo) - Actor.same + Behaviors.same case "pong" ⇒ probe ! "ok" - Actor.same + Behaviors.same case "actorOf" ⇒ val child = ctx.actorOf(untyped1) child.tell("ping", ctx.self.toUntyped) - Actor.same + Behaviors.same case "watch" ⇒ ctx.watch(ref) - Actor.same + Behaviors.same case "supervise-stop" ⇒ val child = ctx.actorOf(untyped1) ctx.watch(child) child ! ThrowIt3 child.tell("ping", ctx.self.toUntyped) - Actor.same + Behaviors.same case "stop-child" ⇒ val child = ctx.actorOf(untyped1) ctx.watch(child) ctx.stop(child) - Actor.same + Behaviors.same } } onSignal { case (ctx, Terminated(ref)) ⇒ probe ! "terminated" - Actor.same + Behaviors.same } sealed trait Typed2Msg @@ -131,13 +131,13 @@ object AdapterSpec { } def typed2: Behavior[Typed2Msg] = - Actor.immutable { (ctx, msg) ⇒ + Behaviors.immutable { (ctx, msg) ⇒ msg match { case Ping(replyTo) ⇒ replyTo ! "pong" - Actor.same + Behaviors.same case StopIt ⇒ - Actor.stopped + Behaviors.stopped case t: ThrowIt ⇒ throw t } @@ -188,7 +188,7 @@ class AdapterSpec extends AkkaSpec { "spawn typed child from untyped parent" in { val probe = TestProbe() - val ign = system.spawnAnonymous(Actor.ignore[Ping]) + val ign = system.spawnAnonymous(Behaviors.ignore[Ping]) val untypedRef = system.actorOf(untyped2(ign, probe.ref)) untypedRef ! "spawn" probe.expectMsg("ok") @@ -196,7 +196,7 @@ class AdapterSpec extends AkkaSpec { "actorOf typed child via Props from untyped parent" in { val probe = TestProbe() - val ign = system.spawnAnonymous(Actor.ignore[Ping]) + val ign = system.spawnAnonymous(Behaviors.ignore[Ping]) val untypedRef = system.actorOf(untyped2(ign, probe.ref)) untypedRef ! "actorOf-props" probe.expectMsg("ok") @@ -230,7 +230,7 @@ class AdapterSpec extends AkkaSpec { "supervise typed child from untyped parent" in { val probe = TestProbe() - val ign = system.spawnAnonymous(Actor.ignore[Ping]) + val ign = system.spawnAnonymous(Behaviors.ignore[Ping]) val untypedRef = system.actorOf(untyped2(ign, probe.ref)) untypedRef ! "supervise-stop" @@ -260,7 +260,7 @@ class AdapterSpec extends AkkaSpec { "stop typed child from untyped parent" in { val probe = TestProbe() - val ignore = system.spawnAnonymous(Actor.ignore[Ping]) + val ignore = system.spawnAnonymous(Behaviors.ignore[Ping]) val untypedRef = system.actorOf(untyped2(ignore, probe.ref)) untypedRef ! "stop-child" probe.expectMsg("terminated") 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 571b5ae88c..b3d8866b16 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 @@ -4,16 +4,21 @@ package docs.akka.typed //#imports -import akka.actor.typed._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.ActorRef +import akka.actor.typed.ActorSystem +import akka.actor.typed.Behavior +import akka.actor.typed.Terminated import akka.actor.typed.scaladsl.AskPattern._ +import akka.actor.typed.scaladsl.Behaviors import akka.testkit.typed.TestKit +import scala.concurrent.Await import scala.concurrent.Future import scala.concurrent.duration._ -import scala.concurrent.Await //#imports +import akka.actor.typed.TypedAkkaSpecWithShutdown + object IntroSpec { //#hello-world-actor @@ -21,10 +26,10 @@ object IntroSpec { final case class Greet(whom: String, replyTo: ActorRef[Greeted]) final case class Greeted(whom: String) - val greeter = Actor.immutable[Greet] { (_, msg) ⇒ + val greeter = Behaviors.immutable[Greet] { (_, msg) ⇒ println(s"Hello ${msg.whom}!") msg.replyTo ! Greeted(msg.whom) - Actor.same + Behaviors.same } } //#hello-world-actor @@ -55,7 +60,7 @@ object IntroSpec { chatRoom(List.empty) private def chatRoom(sessions: List[ActorRef[SessionEvent]]): Behavior[Command] = - Actor.immutable[Command] { (ctx, msg) ⇒ + Behaviors.immutable[Command] { (ctx, msg) ⇒ msg match { case GetSession(screenName, client) ⇒ val wrapper = ctx.spawnAdapter { @@ -66,7 +71,7 @@ object IntroSpec { case PostSessionMessage(screenName, message) ⇒ val mp = MessagePosted(screenName, message) sessions foreach (_ ! mp) - Actor.same + Behaviors.same } } //#chatroom-behavior @@ -106,38 +111,38 @@ class IntroSpec extends TestKit with TypedAkkaSpecWithShutdown { import ChatRoom._ val gabbler = - Actor.immutable[SessionEvent] { (_, msg) ⇒ + Behaviors.immutable[SessionEvent] { (_, msg) ⇒ msg match { //#chatroom-gabbler // We document that the compiler warns about the missing handler for `SessionDenied` case SessionDenied(reason) ⇒ println(s"cannot start chat room session: $reason") - Actor.stopped + Behaviors.stopped //#chatroom-gabbler case SessionGranted(handle) ⇒ handle ! PostMessage("Hello World!") - Actor.same + Behaviors.same case MessagePosted(screenName, message) ⇒ println(s"message has been posted by '$screenName': $message") - Actor.stopped + Behaviors.stopped } } //#chatroom-gabbler //#chatroom-main val main: Behavior[String] = - Actor.deferred { ctx ⇒ + Behaviors.deferred { ctx ⇒ val chatRoom = ctx.spawn(ChatRoom.behavior, "chatroom") val gabblerRef = ctx.spawn(gabbler, "gabbler") ctx.watch(gabblerRef) - Actor.immutablePartial[String] { + Behaviors.immutablePartial[String] { case (_, "go") ⇒ chatRoom ! GetSession("ol’ Gabbler", gabblerRef) - Actor.same + Behaviors.same } onSignal { case (_, Terminated(ref)) ⇒ - Actor.stopped + Behaviors.stopped } } 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 5c6982f052..b18b5fbc17 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 @@ -5,7 +5,7 @@ package docs.akka.typed //#imports import akka.actor.typed._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.ActorContext import akka.testkit.typed.TestKit @@ -38,9 +38,9 @@ object MutableIntroSpec { //#chatroom-behavior def behavior(): Behavior[Command] = - Actor.mutable[Command](ctx ⇒ new ChatRoomBehavior(ctx)) + Behaviors.mutable[Command](ctx ⇒ new ChatRoomBehavior(ctx)) - class ChatRoomBehavior(ctx: ActorContext[Command]) extends Actor.MutableBehavior[Command] { + class ChatRoomBehavior(ctx: ActorContext[Command]) extends Behaviors.MutableBehavior[Command] { private var sessions: List[ActorRef[SessionEvent]] = List.empty override def onMessage(msg: Command): Behavior[Command] = { @@ -76,36 +76,36 @@ class MutableIntroSpec extends TestKit with TypedAkkaSpecWithShutdown { import ChatRoom._ val gabbler = - Actor.immutable[SessionEvent] { (_, msg) ⇒ + Behaviors.immutable[SessionEvent] { (_, msg) ⇒ msg match { case SessionDenied(reason) ⇒ println(s"cannot start chat room session: $reason") - Actor.stopped + Behaviors.stopped case SessionGranted(handle) ⇒ handle ! PostMessage("Hello World!") - Actor.same + Behaviors.same case MessagePosted(screenName, message) ⇒ println(s"message has been posted by '$screenName': $message") - Actor.stopped + Behaviors.stopped } } //#chatroom-gabbler //#chatroom-main val main: Behavior[String] = - Actor.deferred { ctx ⇒ + Behaviors.deferred { ctx ⇒ val chatRoom = ctx.spawn(ChatRoom.behavior(), "chatroom") val gabblerRef = ctx.spawn(gabbler, "gabbler") ctx.watch(gabblerRef) - Actor.immutablePartial[String] { + Behaviors.immutablePartial[String] { case (_, "go") ⇒ chatRoom ! GetSession("ol’ Gabbler", gabblerRef) - Actor.same + Behaviors.same } onSignal { case (_, Terminated(_)) ⇒ println("Stopping guardian") - Actor.stopped + Behaviors.stopped } } 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 a3fc54daa9..a3b29177b0 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 @@ -1,7 +1,7 @@ package docs.akka.typed.coexistence import akka.actor.typed._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.testkit.TestKit //#adapter-import // adds support for typed actors to an untyped actor system and context @@ -23,7 +23,7 @@ object TypedWatchingUntypedSpec { case object Pong extends Command val behavior: Behavior[Command] = - Actor.deferred { context ⇒ + Behaviors.deferred { context ⇒ // context.spawn is an implicit extension method val untyped = context.actorOf(Untyped.props(), "second") @@ -33,15 +33,15 @@ object TypedWatchingUntypedSpec { // illustrating how to pass sender, toUntyped is an implicit extension method untyped.tell(Typed.Ping(context.self), context.self.toUntyped) - Actor.immutablePartial[Command] { + Behaviors.immutablePartial[Command] { case (ctx, Pong) ⇒ // it's not possible to get the sender, that must be sent in message // context.stop is an implicit extension method ctx.stop(untyped) - Actor.same + Behaviors.same } onSignal { case (_, akka.actor.typed.Terminated(_)) ⇒ - Actor.stopped + Behaviors.stopped } } } diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/UntypedWatchingTypedSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/UntypedWatchingTypedSpec.scala index 5c37b52f7c..7e4b96e0a7 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/UntypedWatchingTypedSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/UntypedWatchingTypedSpec.scala @@ -1,7 +1,7 @@ package docs.akka.typed.coexistence import akka.actor.typed._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.testkit.TestKit //#adapter-import // adds support for typed actors to an untyped actor system and context @@ -53,13 +53,13 @@ object UntypedWatchingTypedSpec { case object Pong val behavior: Behavior[Command] = - Actor.immutable { (ctx, msg) ⇒ + Behaviors.immutable { (ctx, msg) ⇒ msg match { case Ping(replyTo) ⇒ println(s"${ctx.self} got Ping from $replyTo") // replyTo is an untyped actor that has been converted for coexistence replyTo ! Pong - Actor.same + Behaviors.same } } } diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/async/BasicAsyncTestingSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/async/BasicAsyncTestingSpec.scala index 9df4006d82..d38d3cc6b0 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/async/BasicAsyncTestingSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/async/BasicAsyncTestingSpec.scala @@ -1,6 +1,6 @@ package docs.akka.typed.testing.async -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed._ import akka.testkit.typed.TestKit import akka.testkit.typed.scaladsl._ @@ -11,11 +11,11 @@ object BasicAsyncTestingSpec { case class Ping(msg: String, response: ActorRef[Pong]) case class Pong(msg: String) - val echoActor = Actor.immutable[Ping] { (_, msg) ⇒ + val echoActor = Behaviors.immutable[Ping] { (_, msg) ⇒ msg match { case Ping(m, replyTo) ⇒ replyTo ! Pong(m) - Actor.same + Behaviors.same } } //#under-test diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/sync/BasicSyncTestingSpec.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/sync/BasicSyncTestingSpec.scala index 8b4abba9b8..9fc6000846 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/sync/BasicSyncTestingSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/testing/sync/BasicSyncTestingSpec.scala @@ -10,8 +10,8 @@ import org.scalatest.{ Matchers, WordSpec } object BasicSyncTestingSpec { //#child - val childActor = Actor.immutable[String] { (_, _) ⇒ - Actor.same[String] + val childActor = Behaviors.immutable[String] { (_, _) ⇒ + Behaviors.same[String] } //#child @@ -23,24 +23,24 @@ object BasicSyncTestingSpec { case object SayHelloToAnonymousChild extends Cmd case class SayHello(who: ActorRef[String]) extends Cmd - val myBehaviour = Actor.immutablePartial[Cmd] { + val myBehaviour = Behaviors.immutablePartial[Cmd] { case (ctx, CreateChild(name)) ⇒ ctx.spawn(childActor, name) - Actor.same + Behaviors.same case (ctx, CreateAnonymousChild) ⇒ ctx.spawnAnonymous(childActor) - Actor.same + Behaviors.same case (ctx, SayHelloToChild(childName)) ⇒ val child: ActorRef[String] = ctx.spawn(childActor, childName) child ! "hello" - Actor.same + Behaviors.same case (ctx, SayHelloToAnonymousChild) ⇒ val child: ActorRef[String] = ctx.spawnAnonymous(childActor) child ! "hello stranger" - Actor.same + Behaviors.same case (_, SayHello(who)) ⇒ who ! "hello" - Actor.same + Behaviors.same //#under-test } 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 a62a6d331d..ef8c2a2723 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 @@ -19,7 +19,7 @@ import akka.util.OptionVal * its child actors. * * Behaviors can be formulated in a number of different ways, either by - * using the DSLs in [[akka.actor.typed.scaladsl.Actor]] and [[akka.actor.typed.javadsl.Actor]] + * using the DSLs in [[akka.actor.typed.scaladsl.Behaviors]] and [[akka.actor.typed.javadsl.Behaviors]] * or extending the abstract [[ExtensibleBehavior]] class. * * Closing over ActorContext makes a Behavior immobile: it cannot be moved to @@ -42,7 +42,7 @@ sealed abstract class Behavior[T] { /** * Extension point for implementing custom behaviors in addition to the existing - * set of behaviors available through the DSLs in [[akka.actor.typed.scaladsl.Actor]] and [[akka.actor.typed.javadsl.Actor]] + * set of behaviors available through the DSLs in [[akka.actor.typed.scaladsl.Behaviors]] and [[akka.actor.typed.javadsl.Behaviors]] */ abstract class ExtensibleBehavior[T] extends Behavior[T] { /** 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 327f0a1596..e997a2983c 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,16 +23,16 @@ import akka.actor.typed.ExtensibleBehavior import akka.actor.typed.PreRestart import akka.actor.typed.Signal import akka.actor.typed.SupervisorStrategy._ -import akka.actor.typed.scaladsl.Actor._ +import akka.actor.typed.scaladsl.Behaviors._ import akka.util.OptionVal -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors /** * INTERNAL API */ @InternalApi private[akka] object Restarter { def apply[T, Thr <: Throwable: ClassTag](initialBehavior: Behavior[T], strategy: SupervisorStrategy): Behavior[T] = - Actor.deferred[T] { ctx ⇒ + Behaviors.deferred[T] { ctx ⇒ val c = ctx.asInstanceOf[akka.actor.typed.ActorContext[T]] val startedBehavior = initialUndefer(c, initialBehavior) strategy match { 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 5429d2fa97..f9922be4ca 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.Actor.deferred[T] { ctx ⇒ + scaladsl.Behaviors.deferred[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/receptionist/ReceptionistImpl.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/receptionist/ReceptionistImpl.scala index d13a7eaba9..6cfd928292 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 @@ -9,9 +9,9 @@ import akka.actor.typed.Behavior import akka.actor.typed.Terminated import akka.actor.typed.receptionist.Receptionist._ import akka.actor.typed.receptionist.ServiceKey -import akka.actor.typed.scaladsl.Actor -import akka.actor.typed.scaladsl.Actor.immutable -import akka.actor.typed.scaladsl.Actor.same +import akka.actor.typed.scaladsl.Behaviors +import akka.actor.typed.scaladsl.Behaviors.immutable +import akka.actor.typed.scaladsl.Behaviors.same import akka.actor.typed.scaladsl.ActorContext import akka.util.TypedMultiMap @@ -63,7 +63,7 @@ private[akka] object ReceptionistImpl extends ReceptionistBehaviorProvider { type SubscriptionRegistry = TypedMultiMap[AbstractServiceKey, SubscriptionsKV] private[akka] def init(externalInterfaceFactory: ActorContext[AllCommands] ⇒ ExternalInterface): Behavior[Command] = - Actor.deferred[AllCommands] { ctx ⇒ + Behaviors.deferred[AllCommands] { ctx ⇒ val externalInterface = externalInterfaceFactory(ctx) behavior( TypedMultiMap.empty[AbstractServiceKey, KV], @@ -85,13 +85,13 @@ 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](Actor.deferred[Nothing] { innerCtx ⇒ + ctx.spawnAnonymous[Nothing](Behaviors.deferred[Nothing] { innerCtx ⇒ innerCtx.watch(target) - Actor.immutable[Nothing]((_, _) ⇒ Actor.same) + Behaviors.immutable[Nothing]((_, _) ⇒ Behaviors.same) .onSignal { case (_, Terminated(`target`)) ⇒ ctx.self ! msg - Actor.stopped + Behaviors.stopped } }) @@ -157,7 +157,7 @@ private[akka] object ReceptionistImpl extends ReceptionistBehaviorProvider { case _: InternalCommand ⇒ // silence compiler exhaustive check - Actor.unhandled + Behaviors.unhandled } } } diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Actor.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala similarity index 98% rename from akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Actor.scala rename to akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala index 9caddb5df9..3b75aedfc5 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Actor.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/Behaviors.scala @@ -11,19 +11,22 @@ import akka.util.OptionVal import akka.japi.function.{ Function2 ⇒ JapiFunction2 } import akka.japi.function.{ Procedure, Procedure2 } import akka.japi.pf.PFBuilder - import akka.actor.typed.Behavior import akka.actor.typed.ExtensibleBehavior import akka.actor.typed.Signal import akka.actor.typed.ActorRef import akka.actor.typed.SupervisorStrategy import akka.actor.typed.scaladsl.{ ActorContext ⇒ SAC } - import akka.actor.typed.internal.BehaviorImpl import akka.actor.typed.internal.Restarter import akka.actor.typed.internal.TimerSchedulerImpl +import akka.annotation.ApiMayChange -object Actor { +/** + * Factories for [[akka.actor.typed.Behavior]]. + */ +@ApiMayChange +object Behaviors { private val _unitFunction = (_: SAC[Any], _: Any) ⇒ () private def unitFunction[T] = _unitFunction.asInstanceOf[((SAC[T], Signal) ⇒ Unit)] @@ -62,11 +65,11 @@ object Actor { * abstract method [[MutableBehavior#onMessage]] and optionally override * [[MutableBehavior#onSignal]]. * - * Instances of this behavior should be created via [[Actor#mutable]] and if + * Instances of this behavior should be created via [[Behaviors#mutable]] and if * the [[ActorContext]] is needed it can be passed as a constructor parameter * from the factory function. * - * @see [[Actor#mutable]] + * @see [[Behaviors#mutable]] */ abstract class MutableBehavior[T] extends ExtensibleBehavior[T] { private var _receive: OptionVal[Receive[T]] = OptionVal.None diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/ReceiveBuilder.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/ReceiveBuilder.scala index 2b7512ddf7..661b9f85ea 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/ReceiveBuilder.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/javadsl/ReceiveBuilder.scala @@ -6,13 +6,13 @@ package akka.actor.typed.javadsl import scala.annotation.tailrec import akka.japi.function.{ Creator, Function, Predicate } -import akka.actor.typed.javadsl.Actor.Receive +import akka.actor.typed.javadsl.Behaviors.Receive import akka.actor.typed.{ Behavior, Signal } import ReceiveBuilder._ import akka.annotation.InternalApi /** - * Used when implementing [[Actor.MutableBehavior]]. + * Used when implementing [[Behaviors.MutableBehavior]]. * * When handling a message or signal, this [[Behavior]] will consider all handlers in the order they were added, * looking for the first handler for which both the type and the (optional) predicate match. @@ -145,7 +145,7 @@ object ReceiveBuilder { } /** - * Receive type for [[Actor.MutableBehavior]] + * Receive type for [[Behaviors.MutableBehavior]] */ private class BuiltReceive[T]( private val messageHandlers: List[Case[T, T]], @@ -163,7 +163,7 @@ private class BuiltReceive[T]( if (cls.isAssignableFrom(msg.getClass) && (predicate.isEmpty || predicate.get.apply(msg))) handler(msg) else receive[M](msg, tail) case _ ⇒ - Actor.unhandled + Behaviors.unhandled } } diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Actor.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala similarity index 96% rename from akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Actor.scala rename to akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala index 89c87232fd..8075cabf23 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Actor.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/scaladsl/Behaviors.scala @@ -10,8 +10,11 @@ import akka.actor.typed.internal.{ BehaviorImpl, Supervisor, TimerSchedulerImpl import scala.reflect.ClassTag import scala.util.control.Exception.Catcher +/** + * Factories for [[akka.actor.typed.Behavior]]. + */ @ApiMayChange -object Actor { +object Behaviors { private val _unitFunction = (_: ActorContext[Any], _: Any) ⇒ () private def unitFunction[T] = _unitFunction.asInstanceOf[((ActorContext[T], Signal) ⇒ Unit)] @@ -38,7 +41,7 @@ object Actor { /** * `deferred` is a factory for a behavior. Creation of the behavior instance is deferred until - * the actor is started, as opposed to [[Actor.immutable]] that creates the behavior instance + * 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. * @@ -70,11 +73,11 @@ object Actor { * abstract method [[MutableBehavior#onMessage]] and optionally override * [[MutableBehavior#onSignal]]. * - * Instances of this behavior should be created via [[Actor#Mutable]] and if + * Instances of this behavior should be created via [[Behaviors#Mutable]] and if * the [[ActorContext]] is needed it can be passed as a constructor parameter * from the factory function. * - * @see [[Actor#Mutable]] + * @see [[Behaviors#Mutable]] */ abstract class MutableBehavior[T] extends ExtensibleBehavior[T] { @throws(classOf[Exception]) @@ -189,7 +192,7 @@ object Actor { * Construct an immutable actor behavior from a partial message handler which treats undefined messages as unhandled. */ def immutablePartial[T](onMessage: PartialFunction[(ActorContext[T], T), Behavior[T]]): Immutable[T] = - Actor.immutable[T] { (ctx, t) ⇒ onMessage.applyOrElse((ctx, t), (_: (ActorContext[T], T)) ⇒ Actor.unhandled[T]) } + Behaviors.immutable[T] { (ctx, t) ⇒ onMessage.applyOrElse((ctx, t), (_: (ActorContext[T], T)) ⇒ Behaviors.unhandled[T]) } /** * Construct an actor behavior that can react to lifecycle signals only. diff --git a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingPersistenceSpec.scala b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingPersistenceSpec.scala index 27dc19a778..62a1395ebc 100644 --- a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingPersistenceSpec.scala +++ b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingPersistenceSpec.scala @@ -4,7 +4,7 @@ package akka.cluster.sharding.typed import akka.actor.typed.{ ActorRef, Behavior, Props, TypedAkkaSpecWithShutdown } -import akka.persistence.typed.scaladsl.PersistentActor +import akka.persistence.typed.scaladsl.PersistentBehaviors import akka.testkit.typed.TestKit import akka.testkit.typed.scaladsl.TestProbe import com.typesafe.config.ConfigFactory @@ -36,10 +36,10 @@ object ClusterShardingPersistenceSpec { final case class Get(replyTo: ActorRef[String]) extends Command final case object StopPlz extends Command - import PersistentActor._ + import PersistentBehaviors._ val persistentActor: Behavior[Command] = - PersistentActor.persistentEntity[Command, String, String]( + PersistentBehaviors.persistentEntity[Command, String, String]( persistenceIdFromActorName = name ⇒ "Test-" + name, initialState = "", commandHandler = (_, state, cmd) ⇒ cmd match { diff --git a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingSpec.scala b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingSpec.scala index 2e08ee3f38..4e3446b0fa 100644 --- a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingSpec.scala +++ b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ClusterShardingSpec.scala @@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets import akka.actor.ExtendedActorSystem import akka.actor.typed.{ ActorRef, ActorRefResolver, Props, TypedAkkaSpecWithShutdown } -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.cluster.MemberStatus import akka.cluster.typed.{ Cluster, Join } @@ -135,31 +135,31 @@ class ClusterShardingSpec extends TestKit("ClusterShardingSpec", ClusterSharding } val typeKey = EntityTypeKey[TestProtocol]("envelope-shard") - val behavior = Actor.immutable[TestProtocol] { + val behavior = Behaviors.immutable[TestProtocol] { case (_, StopPlz()) ⇒ - Actor.stopped + Behaviors.stopped case (ctx, WhoAreYou(replyTo)) ⇒ replyTo ! s"I'm ${ctx.self.path.name}" - Actor.same + Behaviors.same case (_, ReplyPlz(toMe)) ⇒ toMe ! "Hello!" - Actor.same + Behaviors.same } val typeKey2 = EntityTypeKey[IdTestProtocol]("no-envelope-shard") - val behaviorWithId = Actor.immutable[IdTestProtocol] { + val behaviorWithId = Behaviors.immutable[IdTestProtocol] { case (_, IdStopPlz(_)) ⇒ - Actor.stopped + Behaviors.stopped case (ctx, IdWhoAreYou(_, replyTo)) ⇒ replyTo ! s"I'm ${ctx.self.path.name}" - Actor.same + Behaviors.same case (_, IdReplyPlz(_, toMe)) ⇒ toMe ! "Hello!" - Actor.same + Behaviors.same } "Typed cluster sharding" must { 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 19fb42ade2..efd070e71a 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 @@ -13,7 +13,7 @@ import akka.cluster.{ ddata ⇒ dd } import akka.pattern.ask import akka.actor.typed.ActorRef import akka.actor.typed.Behavior -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.util.Timeout import akka.cluster.ddata.ReplicatedData @@ -35,7 +35,7 @@ import akka.actor.typed.Terminated def behavior(settings: dd.ReplicatorSettings, underlyingReplicator: Option[akka.actor.ActorRef]): Behavior[SReplicator.Command] = { - Actor.deferred { ctx ⇒ + Behaviors.deferred { ctx ⇒ val untypedReplicator = underlyingReplicator match { case Some(ref) ⇒ ref case None ⇒ @@ -54,17 +54,17 @@ import akka.actor.typed.Terminated ctx.stop(adapter) withState(subscribeAdapters - subscriber) case None ⇒ // already unsubscribed or terminated - Actor.same + Behaviors.same } } - Actor.immutable[SReplicator.Command] { (ctx, msg) ⇒ + Behaviors.immutable[SReplicator.Command] { (ctx, msg) ⇒ msg match { case cmd: SReplicator.Get[_] ⇒ untypedReplicator.tell( dd.Replicator.Get(cmd.key, cmd.consistency, cmd.request), sender = cmd.replyTo.toUntyped) - Actor.same + Behaviors.same case cmd: JReplicator.Get[d] ⇒ implicit val timeout = Timeout(cmd.consistency.timeout match { @@ -82,13 +82,13 @@ import akka.actor.typed.Terminated case _ ⇒ JReplicator.GetFailure(cmd.key, cmd.request) } reply.foreach { cmd.replyTo ! _ } - Actor.same + Behaviors.same case cmd: SReplicator.Update[_] ⇒ untypedReplicator.tell( dd.Replicator.Update(cmd.key, cmd.writeConsistency, cmd.request)(cmd.modify), sender = cmd.replyTo.toUntyped) - Actor.same + Behaviors.same case cmd: JReplicator.Update[d] ⇒ implicit val timeout = Timeout(cmd.writeConsistency.timeout match { @@ -107,14 +107,14 @@ import akka.actor.typed.Terminated case _ ⇒ JReplicator.UpdateTimeout(cmd.key, cmd.request) } reply.foreach { cmd.replyTo ! _ } - Actor.same + Behaviors.same case cmd: SReplicator.Subscribe[_] ⇒ // For the Scala API the Changed messages can be sent directly to the subscriber untypedReplicator.tell( dd.Replicator.Subscribe(cmd.key, cmd.subscriber.toUntyped), sender = cmd.subscriber.toUntyped) - Actor.same + Behaviors.same case cmd: JReplicator.Subscribe[ReplicatedData] @unchecked ⇒ // For the Java API the Changed messages must be mapped to the JReplicator.Changed class. @@ -134,7 +134,7 @@ import akka.actor.typed.Terminated case InternalChanged(chg, subscriber) ⇒ subscriber ! JReplicator.Changed(chg.key)(chg.dataValue) - Actor.same + Behaviors.same case cmd: JReplicator.Unsubscribe[ReplicatedData] @unchecked ⇒ stopSubscribeAdapter(cmd.subscriber) @@ -143,7 +143,7 @@ import akka.actor.typed.Terminated untypedReplicator.tell( dd.Replicator.Delete(cmd.key, cmd.consistency, cmd.request), sender = cmd.replyTo.toUntyped) - Actor.same + Behaviors.same case cmd: JReplicator.Delete[d] ⇒ implicit val timeout = Timeout(cmd.consistency.timeout match { @@ -162,11 +162,11 @@ import akka.actor.typed.Terminated case _ ⇒ JReplicator.ReplicationDeleteFailure(cmd.key, cmd.request) } reply.foreach { cmd.replyTo ! _ } - Actor.same + Behaviors.same case SReplicator.GetReplicaCount(replyTo) ⇒ untypedReplicator.tell(dd.Replicator.GetReplicaCount, sender = replyTo.toUntyped) - Actor.same + Behaviors.same case JReplicator.GetReplicaCount(replyTo) ⇒ implicit val timeout = Timeout(localAskTimeout) @@ -175,11 +175,11 @@ import akka.actor.typed.Terminated (untypedReplicator ? dd.Replicator.GetReplicaCount) .mapTo[dd.Replicator.ReplicaCount].map(rsp ⇒ JReplicator.ReplicaCount(rsp.n)) reply.foreach { replyTo ! _ } - Actor.same + Behaviors.same case SReplicator.FlushChanges | JReplicator.FlushChanges ⇒ untypedReplicator.tell(dd.Replicator.FlushChanges, sender = akka.actor.ActorRef.noSender) - Actor.same + Behaviors.same } } 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 e37729f3c6..5ccf10a073 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 @@ -10,7 +10,7 @@ import akka.cluster.{ ClusterEvent, MemberStatus } import akka.actor.typed.{ ActorRef, ActorSystem, Terminated } import akka.cluster.typed._ import akka.actor.typed.internal.adapter.ActorSystemAdapter -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ /** @@ -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) = Actor.deferred[ClusterStateSubscription] { ctx ⇒ + private def subscriptionsBehavior(adaptedCluster: akka.cluster.Cluster) = Behaviors.deferred[ClusterStateSubscription] { ctx ⇒ var seenState: SeenState = BeforeUp var upSubscribers: List[ActorRef[SelfUp]] = Nil var removedSubscribers: List[ActorRef[SelfRemoved]] = Nil @@ -51,7 +51,7 @@ private[akka] object AdapterClusterImpl { } } - Actor.immutable[AnyRef] { (ctx, msg) ⇒ + Behaviors.immutable[AnyRef] { (ctx, msg) ⇒ msg match { case Subscribe(subscriber: ActorRef[SelfUp] @unchecked, clazz) if clazz == classOf[SelfUp] ⇒ @@ -64,33 +64,33 @@ private[akka] object AdapterClusterImpl { // self did join, but is now no longer up, we want to avoid subscribing // to not get a memory leak, but also not signal anything } - Actor.same + Behaviors.same case Subscribe(subscriber: ActorRef[SelfRemoved] @unchecked, clazz) if clazz == classOf[SelfRemoved] ⇒ seenState match { case BeforeUp | Up ⇒ removedSubscribers = subscriber :: removedSubscribers case Removed(s) ⇒ subscriber ! SelfRemoved(s) } - Actor.same + Behaviors.same case Subscribe(subscriber, eventClass) ⇒ adaptedCluster.subscribe(subscriber.toUntyped, initialStateMode = ClusterEvent.initialStateAsEvents, eventClass) - Actor.same + Behaviors.same case Unsubscribe(subscriber) ⇒ adaptedCluster.unsubscribe(subscriber.toUntyped) - Actor.same + Behaviors.same case GetCurrentState(sender) ⇒ adaptedCluster.sendCurrentClusterState(sender.toUntyped) - Actor.same + Behaviors.same case evt: MemberEvent if evt.member.uniqueAddress == cluster.selfMember.uniqueAddress ⇒ onSelfMemberEvent(evt) - Actor.same + Behaviors.same case _: MemberEvent ⇒ - Actor.same + Behaviors.same } }.onSignal { @@ -98,28 +98,28 @@ private[akka] object AdapterClusterImpl { case (_, Terminated(ref)) ⇒ upSubscribers = upSubscribers.filterNot(_ == ref) removedSubscribers = removedSubscribers.filterNot(_ == ref) - Actor.same + Behaviors.same }.narrow[ClusterStateSubscription] } - private def managerBehavior(adaptedCluster: akka.cluster.Cluster) = Actor.immutable[ClusterCommand]((ctx, msg) ⇒ + private def managerBehavior(adaptedCluster: akka.cluster.Cluster) = Behaviors.immutable[ClusterCommand]((ctx, msg) ⇒ msg match { case Join(address) ⇒ adaptedCluster.join(address) - Actor.same + Behaviors.same case Leave(address) ⇒ adaptedCluster.leave(address) - Actor.same + Behaviors.same case Down(address) ⇒ adaptedCluster.down(address) - Actor.same + Behaviors.same case JoinSeedNodes(addresses) ⇒ adaptedCluster.joinSeedNodes(addresses) - Actor.same + Behaviors.same } diff --git a/akka-cluster-typed/src/test/java/akka/cluster/ddata/typed/javadsl/ReplicatorTest.java b/akka-cluster-typed/src/test/java/akka/cluster/ddata/typed/javadsl/ReplicatorTest.java index 2705862a19..d7edcda3f7 100644 --- a/akka-cluster-typed/src/test/java/akka/cluster/ddata/typed/javadsl/ReplicatorTest.java +++ b/akka-cluster-typed/src/test/java/akka/cluster/ddata/typed/javadsl/ReplicatorTest.java @@ -24,9 +24,9 @@ import akka.testkit.javadsl.TestKit; import akka.actor.typed.ActorRef; import akka.actor.typed.Behavior; import akka.cluster.ddata.typed.javadsl.Replicator.Command; -import akka.actor.typed.javadsl.Actor; +import akka.actor.typed.javadsl.Behaviors; import akka.actor.typed.javadsl.Adapter; -import akka.actor.typed.javadsl.Actor.MutableBehavior; +import akka.actor.typed.javadsl.Behaviors.MutableBehavior; import akka.actor.typed.javadsl.ActorContext; public class ReplicatorTest extends JUnitSuite { @@ -105,11 +105,11 @@ public class ReplicatorTest extends JUnitSuite { } public static Behavior create(ActorRef replicator, Cluster node) { - return Actor.mutable(ctx -> new Client(replicator, node, ctx)); + return Behaviors.mutable(ctx -> new Client(replicator, node, ctx)); } @Override - public Actor.Receive createReceive() { + public Behaviors.Receive createReceive() { return receiveBuilder() .onMessage(Increment.class, cmd -> { replicator.tell( diff --git a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java index 7c4c6f7858..30aa98bb98 100644 --- a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java +++ b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java @@ -13,8 +13,8 @@ import docs.akka.cluster.typed.BasicClusterManualSpec; //FIXME make these tests public class BasicClusterExampleTest { public void clusterApiExample() { - ActorSystem system = ActorSystem.create(Actor.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); - ActorSystem system2 = ActorSystem.create(Actor.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); + ActorSystem system = ActorSystem.create(Behaviors.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); + ActorSystem system2 = ActorSystem.create(Behaviors.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); try { //#cluster-create @@ -36,8 +36,8 @@ public class BasicClusterExampleTest { } public void clusterLeave() throws Exception { - ActorSystem system = ActorSystem.create(Actor.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); - ActorSystem system2 = ActorSystem.create(Actor.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); + ActorSystem system = ActorSystem.create(Behaviors.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); + ActorSystem system2 = ActorSystem.create(Behaviors.empty(), "ClusterSystem", BasicClusterManualSpec.clusterConfig()); try { Cluster cluster = Cluster.get(system); 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 a25f971d41..27174b1d69 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 @@ -3,7 +3,7 @@ package jdocs.akka.cluster.typed; import akka.actor.typed.ActorRef; import akka.actor.typed.ActorSystem; import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.Actor; +import akka.actor.typed.javadsl.Behaviors; import akka.actor.typed.receptionist.Receptionist; import akka.actor.typed.receptionist.ServiceKey; import scala.concurrent.Await; @@ -27,13 +27,13 @@ public class ReceptionistExampleTest { } static Behavior pingService() { - return Actor.deferred((ctx) -> { + return Behaviors.deferred((ctx) -> { ctx.getSystem().receptionist() .tell(new Receptionist.Register<>(PingServiceKey, ctx.getSelf(), ctx.getSystem().deadLetters())); - return Actor.immutable(Ping.class) + return Behaviors.immutable(Ping.class) .onMessage(Ping.class, (c, msg) -> { msg.replyTo.tell(new Pong()); - return Actor.same(); + return Behaviors.same(); }).build(); }); } @@ -41,12 +41,12 @@ public class ReceptionistExampleTest { //#pinger static Behavior pinger(ActorRef pingService) { - return Actor.deferred((ctx) -> { + return Behaviors.deferred((ctx) -> { pingService.tell(new Ping(ctx.getSelf())); - return Actor.immutable(Pong.class) + return Behaviors.immutable(Pong.class) .onMessage(Pong.class, (c, msg) -> { System.out.println("I was ponged! " + msg); - return Actor.same(); + return Behaviors.same(); }).build(); }); } @@ -54,14 +54,14 @@ public class ReceptionistExampleTest { //#pinger-guardian static Behavior> guardian() { - return Actor.deferred((ctx) -> { + return Behaviors.deferred((ctx) -> { ctx.getSystem().receptionist() .tell(new Receptionist.Subscribe<>(PingServiceKey, ctx.getSelf())); ActorRef ps = ctx.spawnAnonymous(pingService()); ctx.watch(ps); - return Actor.immutable((c, msg) -> { + return Behaviors.immutable((c, msg) -> { msg.getServiceInstances().forEach(ar -> ctx.spawnAnonymous(pinger(ar))); - return Actor.same(); + return Behaviors.same(); }); }); } 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 f611c979ee..9df8fe86c7 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 @@ -6,7 +6,7 @@ package akka.cluster.ddata.typed.scaladsl import akka.actor.Scheduler import akka.actor.typed.{ ActorRef, Behavior, TypedAkkaSpecWithShutdown } import akka.actor.typed.scaladsl.AskPattern._ -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.cluster.Cluster import akka.cluster.ddata.typed.scaladsl.Replicator._ @@ -42,7 +42,7 @@ object ReplicatorSpec { val Key = GCounterKey("counter") def client(replicator: ActorRef[Replicator.Command])(implicit cluster: Cluster): Behavior[ClientCommand] = - Actor.deferred[ClientCommand] { ctx ⇒ + Behaviors.deferred[ClientCommand] { ctx ⇒ val updateResponseAdapter: ActorRef[Replicator.UpdateResponse[GCounter]] = ctx.spawnAdapter(InternalUpdateResponse.apply) @@ -55,30 +55,30 @@ object ReplicatorSpec { replicator ! Replicator.Subscribe(Key, changedAdapter) def behavior(cachedValue: Int): Behavior[ClientCommand] = { - Actor.immutable[ClientCommand] { (ctx, msg) ⇒ + Behaviors.immutable[ClientCommand] { (ctx, msg) ⇒ msg match { case Increment ⇒ replicator ! Replicator.Update(Key, GCounter.empty, Replicator.WriteLocal, updateResponseAdapter)(_ + 1) - Actor.same + Behaviors.same case GetValue(replyTo) ⇒ replicator ! Replicator.Get(Key, Replicator.ReadLocal, getResponseAdapter, Some(replyTo)) - Actor.same + Behaviors.same case GetCachedValue(replyTo) ⇒ replicator ! Replicator.Get(Key, Replicator.ReadLocal, getResponseAdapter, Some(replyTo)) - Actor.same + Behaviors.same case internal: InternalMsg ⇒ internal match { - case InternalUpdateResponse(_) ⇒ Actor.same // ok + case InternalUpdateResponse(_) ⇒ Behaviors.same // ok case InternalGetResponse(rsp @ Replicator.GetSuccess(Key, Some(replyTo: ActorRef[Int] @unchecked))) ⇒ val value = rsp.get(Key).value.toInt replyTo ! value - Actor.same + Behaviors.same case InternalGetResponse(rsp) ⇒ - Actor.unhandled // not dealing with failures + Behaviors.unhandled // not dealing with failures case InternalChanged(chg @ Replicator.Changed(Key)) ⇒ val value = chg.get(Key).value.intValue diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonApiSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonApiSpec.scala index 4a3f58c634..2e5d36e4a4 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonApiSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonApiSpec.scala @@ -6,7 +6,7 @@ package akka.cluster.typed import java.nio.charset.StandardCharsets import akka.actor.ExtendedActorSystem -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.testkit.typed.{ TestKit, TestKitSettings } import akka.testkit.typed.scaladsl.TestProbe @@ -48,15 +48,15 @@ object ClusterSingletonApiSpec { case object Perish extends PingProtocol - val pingPong = Actor.immutable[PingProtocol] { (_, msg) ⇒ + val pingPong = Behaviors.immutable[PingProtocol] { (_, msg) ⇒ msg match { case Ping(respondTo) ⇒ respondTo ! Pong - Actor.same + Behaviors.same case Perish ⇒ - Actor.stopped + Behaviors.stopped } } diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonPersistenceSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonPersistenceSpec.scala index cdafce169e..7e562f619b 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonPersistenceSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/ClusterSingletonPersistenceSpec.scala @@ -5,8 +5,8 @@ package akka.cluster.typed import akka.actor.typed.{ ActorRef, Behavior, Props, TypedAkkaSpecWithShutdown } -import akka.persistence.typed.scaladsl.PersistentActor -import akka.persistence.typed.scaladsl.PersistentActor.{ CommandHandler, Effect } +import akka.persistence.typed.scaladsl.PersistentBehaviors +import akka.persistence.typed.scaladsl.PersistentBehaviors.{ CommandHandler, Effect } import akka.testkit.typed.TestKit import akka.testkit.typed.scaladsl.TestProbe import com.typesafe.config.ConfigFactory @@ -37,7 +37,7 @@ object ClusterSingletonPersistenceSpec { private final case object StopPlz extends Command val persistentActor: Behavior[Command] = - PersistentActor.immutable[Command, String, String]( + PersistentBehaviors.immutable[Command, String, String]( persistenceId = "TheSingleton", initialState = "", commandHandler = (_, state, cmd) ⇒ cmd match { diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteMessageSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteMessageSpec.scala index ea5b6c8c7a..e12cf7f1e0 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteMessageSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteMessageSpec.scala @@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets import akka.Done import akka.testkit.AkkaSpec import akka.actor.typed.{ ActorRef, ActorRefResolver } -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.{ ExtendedActorSystem, ActorSystem ⇒ UntypedActorSystem } import akka.serialization.SerializerWithStringManifest import com.typesafe.config.ConfigFactory @@ -70,12 +70,12 @@ class RemoteMessageSpec extends AkkaSpec(RemoteMessageSpec.config) { "something something" in { val pingPromise = Promise[Done]() - val ponger = Actor.immutable[Ping]((_, msg) ⇒ + val ponger = Behaviors.immutable[Ping]((_, msg) ⇒ msg match { case Ping(sender) ⇒ pingPromise.success(Done) sender ! "pong" - Actor.stopped + Behaviors.stopped }) // typed actor on system1 @@ -91,9 +91,9 @@ class RemoteMessageSpec extends AkkaSpec(RemoteMessageSpec.config) { ActorRefResolver(typedSystem2).resolveActorRef[Ping](remoteRefStr) val pongPromise = Promise[Done]() - val recipient = system2.spawn(Actor.immutable[String] { (_, _) ⇒ + val recipient = system2.spawn(Behaviors.immutable[String] { (_, _) ⇒ pongPromise.success(Done) - Actor.stopped + Behaviors.stopped }, "recipient") remoteRef ! Ping(recipient) diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistSpec.scala index 78923e45ba..89cc676b5c 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistSpec.scala @@ -9,7 +9,7 @@ import akka.actor.ExtendedActorSystem import akka.actor.typed.{ ActorRef, ActorRefResolver, TypedAkkaSpecWithShutdown } import akka.actor.typed.internal.adapter.ActorSystemAdapter import akka.actor.typed.receptionist.{ Receptionist, ServiceKey } -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.adapter._ import akka.cluster.Cluster import akka.serialization.SerializerWithStringManifest @@ -50,14 +50,14 @@ object ClusterReceptionistSpec { case class Ping(respondTo: ActorRef[Pong.type]) extends PingProtocol case object Perish extends PingProtocol - val pingPongBehavior = Actor.immutable[PingProtocol] { (_, msg) ⇒ + val pingPongBehavior = Behaviors.immutable[PingProtocol] { (_, msg) ⇒ msg match { case Ping(respondTo) ⇒ respondTo ! Pong - Actor.same + Behaviors.same case Perish ⇒ - Actor.stopped + Behaviors.stopped } } diff --git a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala index 6041447ef4..7977c2c6fc 100644 --- a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala +++ b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala @@ -61,8 +61,8 @@ class BasicClusterConfigSpec extends WordSpec with ScalaFutures with Eventually akka.cluster.seed-nodes = [ "akka.tcp://ClusterSystem@127.0.0.1:$sys1Port", "akka.tcp://ClusterSystem@127.0.0.1:$sys2Port" ] """) - val system1 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", config(sys1Port).withFallback(configSystem1)) - val system2 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", config(sys2Port).withFallback(configSystem2)) + val system1 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", config(sys1Port).withFallback(configSystem1)) + val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", config(sys2Port).withFallback(configSystem2)) try { val cluster1 = Cluster(system1) val cluster2 = Cluster(system2) @@ -105,8 +105,8 @@ class BasicClusterManualSpec extends WordSpec with ScalaFutures with Eventually "Cluster API" must { "init cluster" in { - val system = ActorSystem[Nothing](Actor.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system2 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + val system = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) try { //#cluster-create @@ -139,9 +139,9 @@ class BasicClusterManualSpec extends WordSpec with ScalaFutures with Eventually } "subscribe to cluster events" in { - implicit val system1 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system2 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system3 = ActorSystem[Nothing](Actor.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + implicit val system1 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + val system3 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) try { val cluster1 = Cluster(system1) 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 ba9e1e680d..8d28b70be3 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,21 +18,21 @@ import scala.collection.immutable.Set object RandomRouter { def router[T](serviceKey: ServiceKey[T]): Behavior[T] = - Actor.deferred[Any] { ctx ⇒ + Behaviors.deferred[Any] { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(serviceKey, ctx.self) def routingBehavior(routees: Vector[ActorRef[T]]): Behavior[Any] = - Actor.immutable { (_, msg) ⇒ + Behaviors.immutable { (_, msg) ⇒ msg match { case Listing(_, services: Set[ActorRef[T]]) ⇒ routingBehavior(services.toVector) case other: T @unchecked ⇒ if (routees.isEmpty) - Actor.unhandled + Behaviors.unhandled else { val i = ThreadLocalRandom.current.nextInt(routees.size) routees(i) ! other - Actor.same + Behaviors.same } } } @@ -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] = - Actor.deferred[Any] { ctx ⇒ + Behaviors.deferred[Any] { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(serviceKey, ctx.self) val cluster = Cluster(ctx.system) @@ -55,7 +55,7 @@ object RandomRouter { cluster.subscriptions ! Subscribe(reachabilityAdapter, classOf[ReachabilityEvent]) def routingBehavior(routees: Vector[ActorRef[T]], unreachable: Set[Address]): Behavior[Any] = - Actor.immutable { (_, msg) ⇒ + Behaviors.immutable { (_, msg) ⇒ msg match { case Listing(_, services: Set[ActorRef[T]]) ⇒ routingBehavior(services.toVector, unreachable) @@ -68,7 +68,7 @@ object RandomRouter { case other: T @unchecked ⇒ if (routees.isEmpty) - Actor.unhandled + Behaviors.unhandled else { val reachableRoutes = if (unreachable.isEmpty) routees @@ -76,7 +76,7 @@ object RandomRouter { val i = ThreadLocalRandom.current.nextInt(reachableRoutes.size) reachableRoutes(i) ! other - Actor.same + Behaviors.same } } } @@ -93,68 +93,68 @@ object PingPongExample { final case object Pong val pingService: Behavior[Ping] = - Actor.deferred { ctx ⇒ + Behaviors.deferred { ctx ⇒ ctx.system.receptionist ! Receptionist.Register(PingServiceKey, ctx.self, ctx.system.deadLetters) - Actor.immutable[Ping] { (_, msg) ⇒ + Behaviors.immutable[Ping] { (_, msg) ⇒ msg match { case Ping(replyTo) ⇒ replyTo ! Pong - Actor.stopped + Behaviors.stopped } } } //#ping-service //#pinger - def pinger(pingService: ActorRef[Ping]) = Actor.deferred[Pong.type] { ctx ⇒ + def pinger(pingService: ActorRef[Ping]) = Behaviors.deferred[Pong.type] { ctx ⇒ pingService ! Ping(ctx.self) - Actor.immutable { (_, msg) ⇒ + Behaviors.immutable { (_, msg) ⇒ println("I was ponged!!" + msg) - Actor.same + Behaviors.same } } //#pinger //#pinger-guardian - val guardian: Behavior[Listing[Ping]] = Actor.deferred { ctx ⇒ + val guardian: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(PingServiceKey, ctx.self) val ps = ctx.spawnAnonymous(pingService) ctx.watch(ps) - Actor.immutablePartial[Listing[Ping]] { + Behaviors.immutablePartial[Listing[Ping]] { case (c, Listing(PingServiceKey, listings)) if listings.nonEmpty ⇒ listings.foreach(ps ⇒ ctx.spawnAnonymous(pinger(ps))) - Actor.same + Behaviors.same } onSignal { case (_, Terminated(`ps`)) ⇒ println("Ping service has shut down") - Actor.stopped + Behaviors.stopped } } //#pinger-guardian //#pinger-guardian-pinger-service - val guardianJustPingService: Behavior[Listing[Ping]] = Actor.deferred { ctx ⇒ + val guardianJustPingService: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ val ps = ctx.spawnAnonymous(pingService) ctx.watch(ps) - Actor.immutablePartial[Listing[Ping]] { + Behaviors.immutablePartial[Listing[Ping]] { case (c, Listing(PingServiceKey, listings)) if listings.nonEmpty ⇒ listings.foreach(ps ⇒ ctx.spawnAnonymous(pinger(ps))) - Actor.same + Behaviors.same } onSignal { case (_, Terminated(`ps`)) ⇒ println("Ping service has shut down") - Actor.stopped + Behaviors.stopped } } //#pinger-guardian-pinger-service //#pinger-guardian-just-pinger - val guardianJustPinger: Behavior[Listing[Ping]] = Actor.deferred { ctx ⇒ + val guardianJustPinger: Behavior[Listing[Ping]] = Behaviors.deferred { ctx ⇒ ctx.system.receptionist ! Receptionist.Subscribe(PingServiceKey, ctx.self) - Actor.immutablePartial[Listing[Ping]] { + Behaviors.immutablePartial[Listing[Ping]] { case (c, Listing(PingServiceKey, listings)) if listings.nonEmpty ⇒ listings.foreach(ps ⇒ ctx.spawnAnonymous(pinger(ps))) - Actor.same + Behaviors.same } } //#pinger-guardian-just-pinger diff --git a/akka-docs/src/main/paradox/actors-typed.md b/akka-docs/src/main/paradox/actors-typed.md index 568541cdcc..270579fbc4 100644 --- a/akka-docs/src/main/paradox/actors-typed.md +++ b/akka-docs/src/main/paradox/actors-typed.md @@ -258,8 +258,8 @@ 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 `Actor.deferred`, which is like a factory for a behavior. -Creation of the behavior instance is deferred until the actor is started, as opposed to `Actor.immutable` +This particular `main` Actor is created using `Behaviors.deferred`, 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. This `main` Actor creates the chat room and the gabbler and the session between them is initiated, and when the diff --git a/akka-docs/src/main/paradox/persistence-typed.md b/akka-docs/src/main/paradox/persistence-typed.md index e31a42f7a3..44bbd089f8 100644 --- a/akka-docs/src/main/paradox/persistence-typed.md +++ b/akka-docs/src/main/paradox/persistence-typed.md @@ -30,16 +30,16 @@ Akka Persistence is a library for building event sourced actors. For background see the @ref:[untyped Akka Persistence section](persistence.md). This documentation shows how the typed API for persistence works and assumes you know what is meant by `Command`, `Event` and `State`. -Let's start with a simple example. The minimum required for a `PersistentActor` is: +Let's start with a simple example. The minimum required for a `PersistentBehavior` is: Scala -: @@snip [BasicPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala) { #structure } +: @@snip [BasicPersistentBehaviorsSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala) { #structure } -The first important thing to notice is the `Behavior` of a `PersistentActor` is typed to the type of the `Command` +The first important thing to notice is the `Behavior` of a persistent actor is typed to the type of the `Command` because this type of message a persistent actor should receive. In Akka Typed this is now enforced by the type system. The event and state are only used internally. -The parameters to `PersistentActor.immutable` are:: +The parameters to `PersistentBehaviors.immutable` are:: * `persistenceId` is the unique identifier for the persistent actor. * `initialState` defines the `State` when the entity is first created e.g. a Counter would start wiht 0 as state. @@ -126,40 +126,40 @@ then it we can look it up with `GetPost`, modify it with `ChangeBody` or publish The state is captured by: Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #state } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #state } The commands (only a subset are valid depending on state): Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #commands } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #commands } The command handler to process each command is decided by a `CommandHandler.byState` command handler, which is a function from `State => CommandHandler`: Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #by-state-command-handler } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #by-state-command-handler } This can refer to many other `CommandHandler`s e.g one for a post that hasn't been started: Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #initial-command-handler } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #initial-command-handler } And a different `CommandHandler` for after the post has been added: Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #post-added-command-handler } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #post-added-command-handler } The event handler is always the same independent of state. The main reason for not making the event handler part of the `CommandHandler` is that all events must be handled and that is typically independent of what the current state is. The event handler can of course still decide what to do based on the state if that is needed. Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #event-handler } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #event-handler } And finally the behavior is created from the `byState` command handler: Scala -: @@snip [InDepthPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala) { #behavior } +: @@snip [InDepthPersistentBehaviorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #behavior } ## Serialization @@ -174,7 +174,7 @@ Since it is strongly discouraged to perform side effects in applyEvent , side effects should be performed once recovery has completed in the `onRecoveryCompleted` callback Scala -: @@snip [BasicPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala) { #recovery } +: @@snip [BasicPersistentBehaviorsSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala) { #recovery } The `onRecoveryCompleted` takes on an `ActorContext` and the current `State`. @@ -184,11 +184,11 @@ Persistence typed allows you to use event tags with the following `withTagging` without using @ref[`EventAdapter`](persistence.md#event-adapters). Scala -: @@snip [BasicPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala) { #tagging } +: @@snip [BasicPersistentActorSpec.scala]($akka$/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala) { #tagging } ## Current limitations -* The `PersistentBehavior` can't be wrapped in other behaviors, such as `Actor.deferred`. See [#23694](https://github.com/akka/akka/issues/23694) +* The `PersistentBehavior` can't be wrapped in other behaviors, such as `Behaviors.deferred`. See [#23694](https://github.com/akka/akka/issues/23694) * Can only tag events with event adapters. See [#23817](https://github.com/akka/akka/issues/23817) * Missing Java DSL. See [#24193](https://github.com/akka/akka/issues/24193) * Snapshot support. See [#24196](https://github.com/akka/akka/issues/24196) diff --git a/akka-persistence-typed/src/main/scala/akka/persistence/typed/internal/PersistentActorImpl.scala b/akka-persistence-typed/src/main/scala/akka/persistence/typed/internal/PersistentActorImpl.scala index f1bc9a9f54..332491c785 100644 --- a/akka-persistence-typed/src/main/scala/akka/persistence/typed/internal/PersistentActorImpl.scala +++ b/akka-persistence-typed/src/main/scala/akka/persistence/typed/internal/PersistentActorImpl.scala @@ -11,7 +11,7 @@ import akka.persistence.RecoveryCompleted import akka.persistence.SnapshotOffer import akka.actor.typed.Signal import akka.actor.typed.internal.adapter.ActorContextAdapter -import akka.persistence.typed.scaladsl.PersistentActor +import akka.persistence.typed.scaladsl.PersistentBehaviors import akka.persistence.typed.scaladsl.PersistentBehavior import akka.actor.typed.scaladsl.ActorContext import akka.actor.typed.Terminated @@ -43,7 +43,7 @@ import akka.persistence.journal.Tagged behavior: PersistentBehavior[C, E, S]) extends UntypedPersistentActor { import PersistentActorImpl._ - import PersistentActor._ + import PersistentBehaviors._ override val persistenceId: String = behavior.persistenceIdFromActorName(self.path.name) diff --git a/akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentActor.scala b/akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentBehaviors.scala similarity index 98% rename from akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentActor.scala rename to akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentBehaviors.scala index 29554c6e00..e7c8ded6dc 100644 --- a/akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentActor.scala +++ b/akka-persistence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentBehaviors.scala @@ -10,7 +10,7 @@ import akka.persistence.typed.internal.PersistentActorImpl import scala.collection.{ immutable ⇒ im } -object PersistentActor { +object PersistentBehaviors { /** * Create a `Behavior` for a persistent actor. @@ -187,11 +187,11 @@ object PersistentActor { class PersistentBehavior[Command, Event, State]( @InternalApi private[akka] val persistenceIdFromActorName: String ⇒ String, val initialState: State, - val commandHandler: PersistentActor.CommandHandler[Command, Event, State], + val commandHandler: PersistentBehaviors.CommandHandler[Command, Event, State], val eventHandler: (State, Event) ⇒ State, val recoveryCompleted: (ActorContext[Command], State) ⇒ Unit, val tagger: Event ⇒ Set[String]) extends UntypedBehavior[Command] { - import PersistentActor._ + import PersistentBehaviors._ /** INTERNAL API */ @InternalApi private[akka] override def untypedProps: akka.actor.Props = PersistentActorImpl.props(() ⇒ this) 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 6837d3512b..0a9f91c7a8 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 @@ -6,13 +6,13 @@ package akka.persistence.typed.scaladsl import scala.concurrent.ExecutionContext import scala.concurrent.duration._ import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, Terminated } -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.ActorContext import akka.actor.typed.scaladsl.TimerScheduler object PersistentActorCompileOnlyTest { - import akka.persistence.typed.scaladsl.PersistentActor._ + import akka.persistence.typed.scaladsl.PersistentBehaviors._ object Simple { //#command @@ -42,7 +42,7 @@ object PersistentActorCompileOnlyTest { //#behavior val simpleBehavior: PersistentBehavior[SimpleCommand, SimpleEvent, ExampleState] = - PersistentActor.immutable[SimpleCommand, SimpleEvent, ExampleState]( + PersistentBehaviors.immutable[SimpleCommand, SimpleEvent, ExampleState]( persistenceId = "sample-id-1", initialState = ExampleState(Nil), commandHandler = commandHandler, @@ -62,7 +62,7 @@ object PersistentActorCompileOnlyTest { case class ExampleState(events: List[String] = Nil) - PersistentActor.immutable[MyCommand, MyEvent, ExampleState]( + PersistentBehaviors.immutable[MyCommand, MyEvent, ExampleState]( persistenceId = "sample-id-1", initialState = ExampleState(Nil), @@ -106,7 +106,7 @@ object PersistentActorCompileOnlyTest { .foreach(sender ! _) } - PersistentActor.immutable[Command, Event, EventsInFlight]( + PersistentBehaviors.immutable[Command, Event, EventsInFlight]( persistenceId = "recovery-complete-id", initialState = EventsInFlight(0, Map.empty), @@ -149,7 +149,7 @@ object PersistentActorCompileOnlyTest { sealed trait Event case class MoodChanged(to: Mood) extends Event - val b: Behavior[Command] = PersistentActor.immutable[Command, Event, Mood]( + val b: Behavior[Command] = PersistentBehaviors.immutable[Command, Event, Mood]( persistenceId = "myPersistenceId", initialState = Happy, commandHandler = CommandHandler.byState { @@ -171,7 +171,7 @@ object PersistentActorCompileOnlyTest { }) // FIXME this doesn't work, wrapping is not supported - Actor.withTimers((timers: TimerScheduler[Command]) ⇒ { + Behaviors.withTimers((timers: TimerScheduler[Command]) ⇒ { timers.startPeriodicTimer("swing", MoodSwing, 10.seconds) b }) @@ -190,7 +190,7 @@ object PersistentActorCompileOnlyTest { case class State(tasksInFlight: List[Task]) - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "asdf", initialState = State(Nil), commandHandler = CommandHandler.command { @@ -217,7 +217,7 @@ object PersistentActorCompileOnlyTest { def worker(task: Task): Behavior[Nothing] = ??? - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "asdf", initialState = State(Nil), commandHandler = (ctx, _, cmd) ⇒ cmd match { @@ -268,7 +268,7 @@ object PersistentActorCompileOnlyTest { def isFullyHydrated(basket: Basket, ids: List[Id]) = basket.items.map(_.id) == ids - Actor.deferred { ctx: ActorContext[Command] ⇒ + Behaviors.deferred { ctx: ActorContext[Command] ⇒ // FIXME this doesn't work, wrapping not supported var basket = Basket(Nil) @@ -280,7 +280,7 @@ object PersistentActorCompileOnlyTest { .persist[Event, List[Id]](ItemAdded(id)) .andThen(metadataRegistry ! GetMetaData(id, adapt)) - PersistentActor.immutable[Command, Event, List[Id]]( + PersistentBehaviors.immutable[Command, Event, List[Id]]( persistenceId = "basket-1", initialState = Nil, commandHandler = @@ -342,7 +342,7 @@ object PersistentActorCompileOnlyTest { if (currentState == newMood) Effect.none else Effect.persist(MoodChanged(newMood)) - PersistentActor.immutable[Command, Event, Mood]( + PersistentBehaviors.immutable[Command, Event, Mood]( persistenceId = "myPersistenceId", initialState = Sad, commandHandler = (_, state, cmd) ⇒ @@ -378,7 +378,7 @@ object PersistentActorCompileOnlyTest { class State - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "myPersistenceId", initialState = new State, commandHandler = CommandHandler.command { 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 e8797203df..f33e1416bf 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 @@ -5,13 +5,13 @@ package akka.persistence.typed.scaladsl import scala.concurrent.duration._ import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, SupervisorStrategy, Terminated, TypedAkkaSpecWithShutdown } -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.testkit.typed.TestKitSettings import akka.testkit.typed.TestKit import akka.testkit.typed.scaladsl._ import com.typesafe.config.ConfigFactory import org.scalatest.concurrent.Eventually -import akka.persistence.typed.scaladsl.PersistentActor._ +import akka.persistence.typed.scaladsl.PersistentBehaviors._ object PersistentActorSpec { @@ -46,7 +46,7 @@ object PersistentActorSpec { def counter(persistenceId: String, loggingActor: ActorRef[String]): Behavior[Command] = { - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId, initialState = State(0, Vector.empty), commandHandler = (ctx, state, cmd) ⇒ cmd match { @@ -57,10 +57,10 @@ object PersistentActorSpec { Effect.none case IncrementLater ⇒ // purpose is to test signals - val delay = ctx.spawnAnonymous(Actor.withTimers[Tick.type] { timers ⇒ + val delay = ctx.spawnAnonymous(Behaviors.withTimers[Tick.type] { timers ⇒ timers.startSingleTimer(Tick, Tick, 10.millis) - Actor.immutable((_, msg) ⇒ msg match { - case Tick ⇒ Actor.stopped + Behaviors.immutable((_, msg) ⇒ msg match { + case Tick ⇒ Behaviors.stopped }) }) ctx.watchWith(delay, DelayFinished) @@ -214,7 +214,7 @@ class PersistentActorSpec extends TestKit(PersistentActorSpec.config) with Event // wrap it in Actor.deferred or Actor.supervise pending val probe = TestProbe[State] - val behavior = Actor.supervise[Command](counter("c13")) + val behavior = Behaviors.supervise[Command](counter("c13")) .onFailure(SupervisorStrategy.restartWithBackoff(1.second, 10.seconds, 0.1)) val c = spawn(behavior) c ! Increment diff --git a/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala b/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala similarity index 78% rename from akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala rename to akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala index 04b0eae45d..e3f963a85c 100644 --- a/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentActorSpec.scala +++ b/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsSpec.scala @@ -4,9 +4,9 @@ package docs.akka.persistence.typed import akka.actor.typed.Behavior -import akka.persistence.typed.scaladsl.PersistentActor +import akka.persistence.typed.scaladsl.PersistentBehaviors -object BasicPersistentActorSpec { +object BasicPersistentBehaviorsSpec { //#structure sealed trait Command @@ -14,7 +14,7 @@ object BasicPersistentActorSpec { case class State() val behavior: Behavior[Command] = - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "abc", initialState = State(), commandHandler = (ctx, state, cmd) ⇒ ???, @@ -23,7 +23,7 @@ object BasicPersistentActorSpec { //#recovery val recoveryBehavior: Behavior[Command] = - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "abc", initialState = State(), commandHandler = (ctx, state, cmd) ⇒ ???, @@ -35,7 +35,7 @@ object BasicPersistentActorSpec { //#tagging val taggingBehavior: Behavior[Command] = - PersistentActor.immutable[Command, Event, State]( + PersistentBehaviors.immutable[Command, Event, State]( persistenceId = "abc", initialState = State(), commandHandler = (ctx, state, cmd) ⇒ ???, diff --git a/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala b/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala similarity index 93% rename from akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala rename to akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala index b3b5ed1bc5..9f241f20bb 100644 --- a/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentActorSpec.scala +++ b/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala @@ -5,10 +5,10 @@ package docs.akka.persistence.typed import akka.Done import akka.actor.typed.{ ActorRef, Behavior } -import akka.persistence.typed.scaladsl.PersistentActor -import akka.persistence.typed.scaladsl.PersistentActor.{ CommandHandler, Effect } +import akka.persistence.typed.scaladsl.PersistentBehaviors +import akka.persistence.typed.scaladsl.PersistentBehaviors.{ CommandHandler, Effect } -object InDepthPersistentActorSpec { +object InDepthPersistentBehaviorSpec { //#event sealed trait BlogEvent extends Serializable @@ -117,7 +117,7 @@ object InDepthPersistentActorSpec { //#behavior def behavior: Behavior[BlogCommand] = - PersistentActor.immutable[BlogCommand, BlogEvent, BlogState]( + PersistentBehaviors.immutable[BlogCommand, BlogEvent, BlogState]( persistenceId = "abc", initialState = BlogState.empty, commandHandler, @@ -125,6 +125,6 @@ object InDepthPersistentActorSpec { //#behavior } -class InDepthPersistentActorSpec { +class InDepthPersistentBehaviorSpec { } diff --git a/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestEventListener.scala b/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestEventListener.scala index 1c7f6a28a1..fa5b4163fc 100644 --- a/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestEventListener.scala +++ b/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestEventListener.scala @@ -5,7 +5,7 @@ import akka.testkit.{ EventFilter, TestEvent ⇒ TE } import akka.event.typed.Logger.{ Command, Initialize } import scala.annotation.tailrec -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.Behavior import akka.event.typed.Logger @@ -23,10 +23,10 @@ import akka.event.typed.Logger class TestEventListener extends Logger with StdOutLogger { override val initialBehavior: Behavior[Command] = { - Actor.deferred[Command] { _ ⇒ - Actor.immutable[Command] { + Behaviors.deferred[Command] { _ ⇒ + Behaviors.immutable[Command] { case (ctx, Initialize(eventStream, replyTo)) ⇒ - val log = ctx.spawn(Actor.deferred[AnyRef] { childCtx ⇒ + val log = ctx.spawn(Behaviors.deferred[AnyRef] { childCtx ⇒ var filters: List[EventFilter] = Nil def filter(event: LogEvent): Boolean = filters exists (f ⇒ try { f(event) } catch { case e: Exception ⇒ false }) @@ -42,17 +42,17 @@ class TestEventListener extends Logger with StdOutLogger { filters = removeFirst(filters) } - Actor.immutable[AnyRef] { + Behaviors.immutable[AnyRef] { case (_, TE.Mute(filters)) ⇒ filters foreach addFilter - Actor.same + Behaviors.same case (_, TE.UnMute(filters)) ⇒ filters foreach removeFilter - Actor.same + Behaviors.same case (_, event: LogEvent) ⇒ if (!filter(event)) print(event) - Actor.same - case _ ⇒ Actor.unhandled + Behaviors.same + case _ ⇒ Behaviors.unhandled } }, "logger") @@ -61,7 +61,7 @@ class TestEventListener extends Logger with StdOutLogger { ctx.watch(log) // sign death pact replyTo ! log - Actor.empty + Behaviors.empty } } } diff --git a/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestKit.scala b/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestKit.scala index fa9be369e7..4521fa1ff7 100644 --- a/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestKit.scala +++ b/akka-testkit-typed/src/main/scala/akka/testkit/typed/TestKit.scala @@ -1,6 +1,6 @@ package akka.testkit.typed -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.scaladsl.AskPattern._ import akka.actor.typed.{ ActorRef, ActorSystem, Behavior } import akka.annotation.ApiMayChange @@ -17,13 +17,13 @@ object TestKit { private[akka] case class SpawnActor[T](name: String, behavior: Behavior[T], replyTo: ActorRef[ActorRef[T]]) extends TestKitCommand private[akka] case class SpawnActorAnonymous[T](behavior: Behavior[T], replyTo: ActorRef[ActorRef[T]]) extends TestKitCommand - private val testKitGuardian = Actor.immutable[TestKitCommand] { + private val testKitGuardian = Behaviors.immutable[TestKitCommand] { case (ctx, SpawnActor(name, behavior, reply)) ⇒ reply ! ctx.spawn(behavior, name) - Actor.same + Behaviors.same case (ctx, SpawnActorAnonymous(behavior, reply)) ⇒ reply ! ctx.spawnAnonymous(behavior) - Actor.same + Behaviors.same } private def getCallerName(clazz: Class[_]): String = { diff --git a/akka-testkit-typed/src/main/scala/akka/testkit/typed/scaladsl/TestProbe.scala b/akka-testkit-typed/src/main/scala/akka/testkit/typed/scaladsl/TestProbe.scala index 6dae757778..912110bebd 100644 --- a/akka-testkit-typed/src/main/scala/akka/testkit/typed/scaladsl/TestProbe.scala +++ b/akka-testkit-typed/src/main/scala/akka/testkit/typed/scaladsl/TestProbe.scala @@ -7,7 +7,7 @@ import scala.concurrent.duration._ import java.util.concurrent.BlockingDeque import akka.actor.typed.Behavior -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.ActorSystem import java.util.concurrent.LinkedBlockingDeque import java.util.concurrent.atomic.AtomicInteger @@ -34,9 +34,9 @@ object TestProbe { def apply[M](name: String)(implicit system: ActorSystem[_]): TestProbe[M] = new TestProbe(name) - private def testActor[M](queue: BlockingDeque[M]): Behavior[M] = Actor.immutable { (ctx, msg) ⇒ + private def testActor[M](queue: BlockingDeque[M]): Behavior[M] = Behaviors.immutable { (ctx, msg) ⇒ queue.offerLast(msg) - Actor.same + Behaviors.same } } diff --git a/akka-testkit-typed/src/test/scala/akka/testkit/typed/BehaviorTestkitSpec.scala b/akka-testkit-typed/src/test/scala/akka/testkit/typed/BehaviorTestkitSpec.scala index a3304a45a4..37d5fb98de 100644 --- a/akka-testkit-typed/src/test/scala/akka/testkit/typed/BehaviorTestkitSpec.scala +++ b/akka-testkit-typed/src/test/scala/akka/testkit/typed/BehaviorTestkitSpec.scala @@ -4,7 +4,7 @@ package akka.testkit.typed -import akka.actor.typed.scaladsl.Actor +import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.{ Behavior, Props } import akka.testkit.typed.BehaviorTestkitSpec.Father._ import akka.testkit.typed.BehaviorTestkitSpec.{ Child, Father } @@ -27,38 +27,38 @@ object BehaviorTestkitSpec { def behavior: Behavior[Command] = init() - def init(): Behavior[Command] = Actor.immutable[Command] { (ctx, msg) ⇒ + def init(): Behavior[Command] = Behaviors.immutable[Command] { (ctx, msg) ⇒ msg match { case SpawnChildren(numberOfChildren) if numberOfChildren > 0 ⇒ 0.until(numberOfChildren).foreach { i ⇒ ctx.spawn(Child.initial, s"child$i") } - Actor.same + Behaviors.same case SpawnChildrenWithProps(numberOfChildren, props) if numberOfChildren > 0 ⇒ 0.until(numberOfChildren).foreach { i ⇒ ctx.spawn(Child.initial, s"child$i", props) } - Actor.same + Behaviors.same case SpawnAnonymous(numberOfChildren) if numberOfChildren > 0 ⇒ 0.until(numberOfChildren).foreach { _ ⇒ ctx.spawnAnonymous(Child.initial) } - Actor.same + Behaviors.same case SpawnAnonymousWithProps(numberOfChildren, props) if numberOfChildren > 0 ⇒ 0.until(numberOfChildren).foreach { _ ⇒ ctx.spawnAnonymous(Child.initial, props) } - Actor.same + Behaviors.same case SpawnAdapter ⇒ ctx.spawnAdapter { r: Reproduce ⇒ SpawnAnonymous(r.times) } - Actor.same + Behaviors.same case SpawnAdapterWithName(name) ⇒ ctx.spawnAdapter({ r: Reproduce ⇒ SpawnAnonymous(r.times) }, name) - Actor.same + Behaviors.same } } } @@ -67,10 +67,10 @@ object BehaviorTestkitSpec { sealed trait Action - val initial: Behavior[Action] = Actor.immutable[Action] { (_, msg) ⇒ + val initial: Behavior[Action] = Behaviors.immutable[Action] { (_, msg) ⇒ msg match { case _ ⇒ - Actor.empty + Behaviors.empty } }