Move name parameter to 2nd pos. in typed system factories (#23244)
This commit is contained in:
parent
e6c2d3f550
commit
ba3f6a6c14
10 changed files with 44 additions and 38 deletions
|
|
@ -43,8 +43,8 @@ public class ExtensionsTest extends JUnitSuite {
|
|||
@Test
|
||||
public void loadJavaExtensionsFromConfig() {
|
||||
final ActorSystem<Object> 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<Object> system = ActorSystem.create("loadScalaExtension", Behavior.empty());
|
||||
final ActorSystem<Object> system = ActorSystem.create(Behavior.empty(), "loadScalaExtension");
|
||||
try {
|
||||
DummyExtension1 instance1 = DummyExtension1.get(system);
|
||||
DummyExtension1 instance2 = DummyExtension1.get(system);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class ActorCompile {
|
|||
Behavior<MyMsg> actor9 = widened(actor7, pf -> pf.match(MyMsgA.class, x -> x));
|
||||
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) -> {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class WatchTest extends JUnitSuite {
|
|||
watched.tell(new Stop());
|
||||
return waitingForTermination(msg.replyTo);
|
||||
});
|
||||
ActorSystem<RunTest<Done>> system = ActorSystem.create("sysname", root);
|
||||
ActorSystem<RunTest<Done>> 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<Message> system = ActorSystem.create("sysname", root);
|
||||
ActorSystem<Message> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class IntroTest {
|
|||
public static void main(String[] args) {
|
||||
//#hello-world
|
||||
final ActorSystem<HelloWorld.Greet> system =
|
||||
ActorSystem.create("hello", HelloWorld.greeter);
|
||||
ActorSystem.create(HelloWorld.greeter, "hello");
|
||||
|
||||
final CompletionStage<HelloWorld.Greeted> reply =
|
||||
AskPattern.ask(system,
|
||||
|
|
@ -198,7 +198,7 @@ public class IntroTest {
|
|||
});
|
||||
|
||||
final ActorSystem<Void> system =
|
||||
ActorSystem.create("ChatRoomDemo", main);
|
||||
ActorSystem.create(main, "ChatRoomDemo");
|
||||
|
||||
Await.result(system.whenTerminated(), Duration.create(3, TimeUnit.SECONDS));
|
||||
//#chatroom-main
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue