Move name parameter to 2nd pos. in typed system factories (#23244)

This commit is contained in:
Heiko Seeberger 2017-07-04 09:13:51 +02:00 committed by Johan Andrén
parent e6c2d3f550
commit ba3f6a6c14
10 changed files with 44 additions and 38 deletions

View file

@ -43,8 +43,8 @@ public class ExtensionsTest extends JUnitSuite {
@Test @Test
public void loadJavaExtensionsFromConfig() { public void loadJavaExtensionsFromConfig() {
final ActorSystem<Object> system = ActorSystem.create( final ActorSystem<Object> system = ActorSystem.create(
"loadJavaExtensionsFromConfig",
Behavior.empty(), Behavior.empty(),
"loadJavaExtensionsFromConfig",
Optional.empty(), Optional.empty(),
Optional.of(ConfigFactory.parseString("akka.typed.extensions += \"akka.typed.ExtensionsTest$MyExtension\"").resolve()), Optional.of(ConfigFactory.parseString("akka.typed.extensions += \"akka.typed.ExtensionsTest$MyExtension\"").resolve()),
Optional.empty(), Optional.empty(),
@ -66,7 +66,7 @@ public class ExtensionsTest extends JUnitSuite {
@Test @Test
public void loadScalaExtension() { public void loadScalaExtension() {
final ActorSystem<Object> system = ActorSystem.create("loadScalaExtension", Behavior.empty()); final ActorSystem<Object> system = ActorSystem.create(Behavior.empty(), "loadScalaExtension");
try { try {
DummyExtension1 instance1 = DummyExtension1.get(system); DummyExtension1 instance1 = DummyExtension1.get(system);
DummyExtension1 instance2 = DummyExtension1.get(system); DummyExtension1 instance2 = DummyExtension1.get(system);

View file

@ -45,7 +45,7 @@ public class ActorCompile {
Behavior<MyMsg> actor9 = widened(actor7, pf -> pf.match(MyMsgA.class, x -> x)); Behavior<MyMsg> actor9 = widened(actor7, pf -> pf.match(MyMsgA.class, x -> x));
Behavior<MyMsg> actor10 = immutable((ctx, msg) -> stopped(actor4), (ctx, signal) -> same()); Behavior<MyMsg> actor10 = immutable((ctx, msg) -> stopped(actor4), (ctx, signal) -> same());
ActorSystem<MyMsg> system = ActorSystem.create("Sys", actor1); ActorSystem<MyMsg> system = ActorSystem.create(actor1, "Sys");
{ {
Actor.<MyMsg>immutable((ctx, msg) -> { Actor.<MyMsg>immutable((ctx, msg) -> {

View file

@ -70,7 +70,7 @@ public class WatchTest extends JUnitSuite {
watched.tell(new Stop()); watched.tell(new Stop());
return waitingForTermination(msg.replyTo); return waitingForTermination(msg.replyTo);
}); });
ActorSystem<RunTest<Done>> system = ActorSystem.create("sysname", root); ActorSystem<RunTest<Done>> system = ActorSystem.create(root, "sysname");
try { try {
// Not sure why this does not compile without an explicit cast? // Not sure why this does not compile without an explicit cast?
// system.tell(new RunTest()); // system.tell(new RunTest());
@ -93,7 +93,7 @@ public class WatchTest extends JUnitSuite {
return unhandled(); return unhandled();
} }
}); });
ActorSystem<Message> system = ActorSystem.create("sysname", root); ActorSystem<Message> system = ActorSystem.create(root, "sysname");
try { try {
// Not sure why this does not compile without an explicit cast? // Not sure why this does not compile without an explicit cast?
// system.tell(new RunTest()); // system.tell(new RunTest());
@ -103,4 +103,4 @@ public class WatchTest extends JUnitSuite {
Await.ready(system.terminate(), Duration.create(10, TimeUnit.SECONDS)); Await.ready(system.terminate(), Duration.create(10, TimeUnit.SECONDS));
} }
} }
} }

View file

@ -58,7 +58,7 @@ public class IntroTest {
public static void main(String[] args) { public static void main(String[] args) {
//#hello-world //#hello-world
final ActorSystem<HelloWorld.Greet> system = final ActorSystem<HelloWorld.Greet> system =
ActorSystem.create("hello", HelloWorld.greeter); ActorSystem.create(HelloWorld.greeter, "hello");
final CompletionStage<HelloWorld.Greeted> reply = final CompletionStage<HelloWorld.Greeted> reply =
AskPattern.ask(system, AskPattern.ask(system,
@ -198,7 +198,7 @@ public class IntroTest {
}); });
final ActorSystem<Void> system = final ActorSystem<Void> system =
ActorSystem.create("ChatRoomDemo", main); ActorSystem.create(main, "ChatRoomDemo");
Await.result(system.whenTerminated(), Duration.create(3, TimeUnit.SECONDS)); Await.result(system.whenTerminated(), Duration.create(3, TimeUnit.SECONDS));
//#chatroom-main //#chatroom-main

View file

@ -95,7 +95,7 @@ class ExtensionsSpec extends TypedSpecSetup {
def `04 handle extensions that fail to initialize`(): Unit = { def `04 handle extensions that fail to initialize`(): Unit = {
def create(): 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$"] 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 = { 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 try f(system) finally system.terminate().futureValue
} }

View file

@ -60,7 +60,7 @@ abstract class TypedSpec(val config: Config) extends TypedSpecSetup {
private var nativeSystemUsed = false private var nativeSystemUsed = false
lazy val nativeSystem: ActorSystem[TypedSpec.Command] = { 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 nativeSystemUsed = true
sys sys
} }

View file

@ -26,11 +26,11 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca
case class Probe(msg: String, replyTo: ActorRef[String]) case class Probe(msg: String, replyTo: ActorRef[String])
trait CommonTests { 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 suite: String
def withSystem[T](name: String, behavior: Behavior[T], doTerminate: Boolean = true)(block: ActorSystem[T] Unit): Terminated = { 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 { try {
block(sys) block(sys)
if (doTerminate) sys.terminate().futureValue else sys.whenTerminated.futureValue 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 = { def `must terminate the guardian actor`(): Unit = {
val inbox = Inbox[String]("terminate") val inbox = Inbox[String]("terminate")
val sys = system("terminate", immutable[Probe] { val sys = system(
case (_, _) unhandled immutable[Probe] {
} onSignal { case (_, _) unhandled
case (ctx, PostStop) } onSignal {
inbox.ref ! "done" case (ctx, PostStop)
same inbox.ref ! "done"
}) same
},
"terminate")
sys.terminate().futureValue sys.terminate().futureValue
inbox.receiveAll() should ===("done" :: Nil) inbox.receiveAll() should ===("done" :: Nil)
} }
@ -98,7 +100,7 @@ class ActorSystemSpec extends Spec with Matchers with BeforeAndAfterAll with Sca
} }
object `An ActorSystemImpl` extends CommonTests { 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" def suite = "native"
// this is essential to complete ActorCellSpec, see there // 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 { 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" def suite = "adapter"
} }
} }

View file

@ -83,7 +83,7 @@ class IntroSpec extends TypedSpec {
// using global pool since we want to run tasks after system.terminate // using global pool since we want to run tasks after system.terminate
import scala.concurrent.ExecutionContext.Implicits.global 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", _)) 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) Await.result(system.whenTerminated, 3.seconds)
//#chatroom-main //#chatroom-main
} }

View file

@ -105,7 +105,7 @@ class MutableIntroSpec extends TypedSpec {
} }
} }
val system = ActorSystem("ChatRoomDemo", main) val system = ActorSystem(main, "ChatRoomDemo")
Await.result(system.whenTerminated, 1.second) Await.result(system.whenTerminated, 1.second)
//#chatroom-main //#chatroom-main
} }

View file

@ -159,11 +159,13 @@ object ActorSystem {
* Akka Typed [[Behavior]] hierarchiesthis system cannot run untyped * Akka Typed [[Behavior]] hierarchiesthis system cannot run untyped
* [[akka.actor.Actor]] instances. * [[akka.actor.Actor]] instances.
*/ */
def apply[T](name: String, guardianBehavior: Behavior[T], def apply[T](
guardianProps: Props = Props.empty, guardianBehavior: Behavior[T],
config: Option[Config] = None, name: String,
classLoader: Option[ClassLoader] = None, guardianProps: Props = Props.empty,
executionContext: Option[ExecutionContext] = None): ActorSystem[T] = { config: Option[Config] = None,
classLoader: Option[ClassLoader] = None,
executionContext: Option[ExecutionContext] = None): ActorSystem[T] = {
Behavior.validateAsInitial(guardianBehavior) Behavior.validateAsInitial(guardianBehavior)
val cl = classLoader.getOrElse(akka.actor.ActorSystem.findClassLoader()) val cl = classLoader.getOrElse(akka.actor.ActorSystem.findClassLoader())
val appConfig = config.getOrElse(ConfigFactory.load(cl)) val appConfig = config.getOrElse(ConfigFactory.load(cl))
@ -175,13 +177,15 @@ object ActorSystem {
* Akka Typed [[Behavior]] hierarchiesthis system cannot run untyped * Akka Typed [[Behavior]] hierarchiesthis system cannot run untyped
* [[akka.actor.Actor]] instances. * [[akka.actor.Actor]] instances.
*/ */
def create[T](name: String, guardianBehavior: Behavior[T], def create[T](
guardianProps: Optional[Props], guardianBehavior: Behavior[T],
config: Optional[Config], name: String,
classLoader: Optional[ClassLoader], guardianProps: Optional[Props],
executionContext: Optional[ExecutionContext]): ActorSystem[T] = { config: Optional[Config],
classLoader: Optional[ClassLoader],
executionContext: Optional[ExecutionContext]): ActorSystem[T] = {
import scala.compat.java8.OptionConverters._ 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]] hierarchiesthis system cannot run untyped * Akka Typed [[Behavior]] hierarchiesthis system cannot run untyped
* [[akka.actor.Actor]] instances. * [[akka.actor.Actor]] instances.
*/ */
def create[T](name: String, guardianBehavior: Behavior[T]): ActorSystem[T] = def create[T](guardianBehavior: Behavior[T], name: String): ActorSystem[T] =
apply(name, guardianBehavior) apply(guardianBehavior, name)
/** /**
* Create an ActorSystem based on the untyped [[akka.actor.ActorSystem]] * Create an ActorSystem based on the untyped [[akka.actor.ActorSystem]]