From ba3f6a6c14dfb621f5efacbaa33ba72a235bcb71 Mon Sep 17 00:00:00 2001 From: Heiko Seeberger Date: Tue, 4 Jul 2017 09:13:51 +0200 Subject: [PATCH] Move name parameter to 2nd pos. in typed system factories (#23244) --- .../test/java/akka/typed/ExtensionsTest.java | 4 +-- .../java/akka/typed/javadsl/ActorCompile.java | 2 +- .../java/akka/typed/javadsl/WatchTest.java | 6 ++-- .../test/java/jdocs/akka/typed/IntroTest.java | 4 +-- .../scala/akka/typed/ExtensionsSpec.scala | 4 +-- .../src/test/scala/akka/typed/TypedSpec.scala | 2 +- .../akka/typed/internal/ActorSystemSpec.scala | 24 ++++++++------- .../scala/docs/akka/typed/IntroSpec.scala | 4 +-- .../docs/akka/typed/MutableIntroSpec.scala | 2 +- .../main/scala/akka/typed/ActorSystem.scala | 30 +++++++++++-------- 10 files changed, 44 insertions(+), 38 deletions(-) diff --git a/akka-typed-tests/src/test/java/akka/typed/ExtensionsTest.java b/akka-typed-tests/src/test/java/akka/typed/ExtensionsTest.java index 86b5d78d68..279c058357 100644 --- a/akka-typed-tests/src/test/java/akka/typed/ExtensionsTest.java +++ b/akka-typed-tests/src/test/java/akka/typed/ExtensionsTest.java @@ -43,8 +43,8 @@ public class ExtensionsTest extends JUnitSuite { @Test public void loadJavaExtensionsFromConfig() { final ActorSystem system = ActorSystem.create( - "loadJavaExtensionsFromConfig", Behavior.empty(), + "loadJavaExtensionsFromConfig", Optional.empty(), Optional.of(ConfigFactory.parseString("akka.typed.extensions += \"akka.typed.ExtensionsTest$MyExtension\"").resolve()), Optional.empty(), @@ -66,7 +66,7 @@ public class ExtensionsTest extends JUnitSuite { @Test public void loadScalaExtension() { - final ActorSystem system = ActorSystem.create("loadScalaExtension", Behavior.empty()); + final ActorSystem system = ActorSystem.create(Behavior.empty(), "loadScalaExtension"); try { DummyExtension1 instance1 = DummyExtension1.get(system); DummyExtension1 instance2 = DummyExtension1.get(system); diff --git a/akka-typed-tests/src/test/java/akka/typed/javadsl/ActorCompile.java b/akka-typed-tests/src/test/java/akka/typed/javadsl/ActorCompile.java index 0364491777..c9119f38a1 100644 --- a/akka-typed-tests/src/test/java/akka/typed/javadsl/ActorCompile.java +++ b/akka-typed-tests/src/test/java/akka/typed/javadsl/ActorCompile.java @@ -45,7 +45,7 @@ public class ActorCompile { Behavior actor9 = widened(actor7, pf -> pf.match(MyMsgA.class, x -> x)); Behavior actor10 = immutable((ctx, msg) -> stopped(actor4), (ctx, signal) -> same()); - ActorSystem system = ActorSystem.create("Sys", actor1); + ActorSystem system = ActorSystem.create(actor1, "Sys"); { Actor.immutable((ctx, msg) -> { diff --git a/akka-typed-tests/src/test/java/akka/typed/javadsl/WatchTest.java b/akka-typed-tests/src/test/java/akka/typed/javadsl/WatchTest.java index c8da9ddfd0..0f1e0f3b27 100644 --- a/akka-typed-tests/src/test/java/akka/typed/javadsl/WatchTest.java +++ b/akka-typed-tests/src/test/java/akka/typed/javadsl/WatchTest.java @@ -70,7 +70,7 @@ public class WatchTest extends JUnitSuite { watched.tell(new Stop()); return waitingForTermination(msg.replyTo); }); - ActorSystem> system = ActorSystem.create("sysname", root); + ActorSystem> system = ActorSystem.create(root, "sysname"); try { // Not sure why this does not compile without an explicit cast? // system.tell(new RunTest()); @@ -93,7 +93,7 @@ public class WatchTest extends JUnitSuite { return unhandled(); } }); - ActorSystem system = ActorSystem.create("sysname", root); + ActorSystem system = ActorSystem.create(root, "sysname"); try { // Not sure why this does not compile without an explicit cast? // system.tell(new RunTest()); @@ -103,4 +103,4 @@ public class WatchTest extends JUnitSuite { Await.ready(system.terminate(), Duration.create(10, TimeUnit.SECONDS)); } } -} \ No newline at end of file +} diff --git a/akka-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java b/akka-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java index 5d59744b7d..6392a2fc2b 100644 --- a/akka-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java +++ b/akka-typed-tests/src/test/java/jdocs/akka/typed/IntroTest.java @@ -58,7 +58,7 @@ public class IntroTest { public static void main(String[] args) { //#hello-world final ActorSystem system = - ActorSystem.create("hello", HelloWorld.greeter); + ActorSystem.create(HelloWorld.greeter, "hello"); final CompletionStage reply = AskPattern.ask(system, @@ -198,7 +198,7 @@ public class IntroTest { }); final ActorSystem system = - ActorSystem.create("ChatRoomDemo", main); + ActorSystem.create(main, "ChatRoomDemo"); Await.result(system.whenTerminated(), Duration.create(3, TimeUnit.SECONDS)); //#chatroom-main diff --git a/akka-typed-tests/src/test/scala/akka/typed/ExtensionsSpec.scala b/akka-typed-tests/src/test/scala/akka/typed/ExtensionsSpec.scala index 0899dfb337..f7c4e4974b 100644 --- a/akka-typed-tests/src/test/scala/akka/typed/ExtensionsSpec.scala +++ b/akka-typed-tests/src/test/scala/akka/typed/ExtensionsSpec.scala @@ -95,7 +95,7 @@ class ExtensionsSpec extends TypedSpecSetup { def `04 handle extensions that fail to initialize`(): Unit = { def create(): Unit = { - ActorSystem[Any]("ExtensionsSpec04", Behavior.EmptyBehavior, config = Some(ConfigFactory.parseString( + ActorSystem[Any](Behavior.EmptyBehavior, "ExtensionsSpec04", config = Some(ConfigFactory.parseString( """ akka.typed.extensions = ["akka.typed.FailingToLoadExtension$"] """))) @@ -153,7 +153,7 @@ class ExtensionsSpec extends TypedSpecSetup { } def withEmptyActorSystem[T](name: String, config: Option[Config] = None)(f: ActorSystem[_] ⇒ T): T = { - val system = ActorSystem[Any](name, Behavior.EmptyBehavior, config = config) + val system = ActorSystem[Any](Behavior.EmptyBehavior, name, config = config) try f(system) finally system.terminate().futureValue } diff --git a/akka-typed-tests/src/test/scala/akka/typed/TypedSpec.scala b/akka-typed-tests/src/test/scala/akka/typed/TypedSpec.scala index e4460568b9..e2b0a6b886 100644 --- a/akka-typed-tests/src/test/scala/akka/typed/TypedSpec.scala +++ b/akka-typed-tests/src/test/scala/akka/typed/TypedSpec.scala @@ -60,7 +60,7 @@ abstract class TypedSpec(val config: Config) extends TypedSpecSetup { private var nativeSystemUsed = false lazy val nativeSystem: ActorSystem[TypedSpec.Command] = { - val sys = ActorSystem(AkkaSpec.getCallerName(classOf[TypedSpec]), guardian(), config = Some(config withFallback AkkaSpec.testConf)) + val sys = ActorSystem(guardian(), AkkaSpec.getCallerName(classOf[TypedSpec]), config = Some(config withFallback AkkaSpec.testConf)) nativeSystemUsed = true sys } diff --git a/akka-typed-tests/src/test/scala/akka/typed/internal/ActorSystemSpec.scala b/akka-typed-tests/src/test/scala/akka/typed/internal/ActorSystemSpec.scala index 003358eec1..182deccba5 100644 --- a/akka-typed-tests/src/test/scala/akka/typed/internal/ActorSystemSpec.scala +++ b/akka-typed-tests/src/test/scala/akka/typed/internal/ActorSystemSpec.scala @@ -26,11 +26,11 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca case class Probe(msg: String, replyTo: ActorRef[String]) trait CommonTests { - def system[T](name: String, behavior: Behavior[T]): ActorSystem[T] + def system[T](behavior: Behavior[T], name: String): ActorSystem[T] def suite: String def withSystem[T](name: String, behavior: Behavior[T], doTerminate: Boolean = true)(block: ActorSystem[T] ⇒ Unit): Terminated = { - val sys = system(s"$suite-$name", behavior) + val sys = system(behavior, s"$suite-$name") try { block(sys) if (doTerminate) sys.terminate().futureValue else sys.whenTerminated.futureValue @@ -55,13 +55,15 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca def `must terminate the guardian actor`(): Unit = { val inbox = Inbox[String]("terminate") - val sys = system("terminate", immutable[Probe] { - case (_, _) ⇒ unhandled - } onSignal { - case (ctx, PostStop) ⇒ - inbox.ref ! "done" - same - }) + val sys = system( + immutable[Probe] { + case (_, _) ⇒ unhandled + } onSignal { + case (ctx, PostStop) ⇒ + inbox.ref ! "done" + same + }, + "terminate") sys.terminate().futureValue inbox.receiveAll() should ===("done" :: Nil) } @@ -98,7 +100,7 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca } object `An ActorSystemImpl` extends CommonTests { - def system[T](name: String, behavior: Behavior[T]): ActorSystem[T] = ActorSystem(name, behavior) + def system[T](behavior: Behavior[T], name: String) = ActorSystem(behavior, name) def suite = "native" // this is essential to complete ActorCellSpec, see there @@ -133,7 +135,7 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca } object `An ActorSystemAdapter` extends CommonTests { - def system[T](name: String, behavior: Behavior[T]): ActorSystem[T] = ActorSystem.adapter(name, behavior) + def system[T](behavior: Behavior[T], name: String) = ActorSystem.adapter(name, behavior) def suite = "adapter" } } diff --git a/akka-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala b/akka-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala index 65214cacfe..3982d839b5 100644 --- a/akka-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala +++ b/akka-typed-tests/src/test/scala/docs/akka/typed/IntroSpec.scala @@ -83,7 +83,7 @@ class IntroSpec extends TypedSpec { // using global pool since we want to run tasks after system.terminate import scala.concurrent.ExecutionContext.Implicits.global - val system: ActorSystem[Greet] = ActorSystem("hello", greeter) + val system: ActorSystem[Greet] = ActorSystem(greeter, "hello") val future: Future[Greeted] = system ? (Greet("world", _)) @@ -133,7 +133,7 @@ class IntroSpec extends TypedSpec { } } - val system = ActorSystem("ChatRoomDemo", main) + val system = ActorSystem(main, "ChatRoomDemo") Await.result(system.whenTerminated, 3.seconds) //#chatroom-main } diff --git a/akka-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala b/akka-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala index 8b86e518a7..1aa03008ae 100644 --- a/akka-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala +++ b/akka-typed-tests/src/test/scala/docs/akka/typed/MutableIntroSpec.scala @@ -105,7 +105,7 @@ class MutableIntroSpec extends TypedSpec { } } - val system = ActorSystem("ChatRoomDemo", main) + val system = ActorSystem(main, "ChatRoomDemo") Await.result(system.whenTerminated, 1.second) //#chatroom-main } diff --git a/akka-typed/src/main/scala/akka/typed/ActorSystem.scala b/akka-typed/src/main/scala/akka/typed/ActorSystem.scala index b0f9092d06..323f3ee53f 100644 --- a/akka-typed/src/main/scala/akka/typed/ActorSystem.scala +++ b/akka-typed/src/main/scala/akka/typed/ActorSystem.scala @@ -159,11 +159,13 @@ object ActorSystem { * Akka Typed [[Behavior]] hierarchies—this system cannot run untyped * [[akka.actor.Actor]] instances. */ - def apply[T](name: String, guardianBehavior: Behavior[T], - guardianProps: Props = Props.empty, - config: Option[Config] = None, - classLoader: Option[ClassLoader] = None, - executionContext: Option[ExecutionContext] = None): ActorSystem[T] = { + def apply[T]( + guardianBehavior: Behavior[T], + name: String, + guardianProps: Props = Props.empty, + config: Option[Config] = None, + classLoader: Option[ClassLoader] = None, + executionContext: Option[ExecutionContext] = None): ActorSystem[T] = { Behavior.validateAsInitial(guardianBehavior) val cl = classLoader.getOrElse(akka.actor.ActorSystem.findClassLoader()) val appConfig = config.getOrElse(ConfigFactory.load(cl)) @@ -175,13 +177,15 @@ object ActorSystem { * Akka Typed [[Behavior]] hierarchies—this system cannot run untyped * [[akka.actor.Actor]] instances. */ - def create[T](name: String, guardianBehavior: Behavior[T], - guardianProps: Optional[Props], - config: Optional[Config], - classLoader: Optional[ClassLoader], - executionContext: Optional[ExecutionContext]): ActorSystem[T] = { + def create[T]( + guardianBehavior: Behavior[T], + name: String, + guardianProps: Optional[Props], + config: Optional[Config], + classLoader: Optional[ClassLoader], + executionContext: Optional[ExecutionContext]): ActorSystem[T] = { import scala.compat.java8.OptionConverters._ - apply(name, guardianBehavior, guardianProps.asScala.getOrElse(EmptyProps), config.asScala, classLoader.asScala, executionContext.asScala) + apply(guardianBehavior, name, guardianProps.asScala.getOrElse(EmptyProps), config.asScala, classLoader.asScala, executionContext.asScala) } /** @@ -189,8 +193,8 @@ object ActorSystem { * Akka Typed [[Behavior]] hierarchies—this system cannot run untyped * [[akka.actor.Actor]] instances. */ - def create[T](name: String, guardianBehavior: Behavior[T]): ActorSystem[T] = - apply(name, guardianBehavior) + def create[T](guardianBehavior: Behavior[T], name: String): ActorSystem[T] = + apply(guardianBehavior, name) /** * Create an ActorSystem based on the untyped [[akka.actor.ActorSystem]]