Add more explicit docs of top level coexistence (#29921)

This commit is contained in:
Justin Pihony 2021-05-25 09:12:49 -04:00 committed by GitHub
parent aa03e8b089
commit b989c4cf3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -90,6 +90,16 @@ Java
@java[To convert between typed and classic `ActorSystem`, `ActorContext` and `ActorRef` in both directions there are adapter methods in `akka.actor.typed.javadsl.Adapter`.]
Note the inline comments in the example above.
This method of using a top level classic actor is the suggested path for this type of co-existence. However, if you prefer to start with a typed top level actor then you can use the @scala[implicit `spawn` -method]@java[`Adapter.spawn`] directly from the typed system:
Scala
: @@snip [TypedWatchingClassicSpec.scala](/akka-actor-typed-tests/src/test/scala/docs/akka/typed/coexistence/TypedWatchingClassicSpec.scala) { #create }
Java
: @@snip [TypedWatchingClassicTest.java](/akka-actor-typed-tests/src/test/java/jdocs/akka/typed/coexistence/TypedWatchingClassicTest.java) { #create }
The above classic-typed difference is further elaborated in @ref:[the `ActorSystem` section](./from-classic.md#actorsystem) of "Learning Akka Typed from Classic".
## Typed to classic
Let's turn the example upside down and first start the typed actor and then the classic as a child.
@ -145,4 +155,3 @@ the child, for example if a classic actor creates a typed child, its default sup
actor creates a classic child, its default supervision will be to restart.

View file

@ -159,7 +159,10 @@ typically performed from the "outside".
The `actorOf` method of the classic `ActorSystem` is typically used to create a few (or many) top level actors. The
`ActorSystem` in Typed doesn't have that capability. Instead, such actors are started as children of
the user guardian actor or children of other actors in the actor hierarchy.
the user guardian actor or children of other actors in the actor hierarchy. The rationale for this is partly about consistency.
In a typed system you cant create children to an arbitrary actor from anywhere in your app without messaging it,
so this will also hold true for the user guardian actor. That noted, in cases where you do need to spawn outside of this guardian
then you can use the @ref:[`SpawnProtocol`](./actor-lifecycle.md#spawnprotocol) to spawn as needed.
## become