Reputation: 163
I want to understand the syntax of creating the actors with default constructor,
object Main extends App {
val system = ActorSystem("MySystem")
val myActor = system.actorOf(Props[MyActor], name = "myactor")
In the above, we are first creating a ActorSystem, and the explanation says that the call to actorOf returns an instance of ActorRef, what is the ActorRef here ? and why is name = "myactor" is used, what does it represent ? and where does the "MySystem" come from ? and Props[MyActor], what does it mean? Can anyone give me a brief explanation of this whole actor creation process in Scala and Akka ?
Upvotes: 0
Views: 255
Reputation: 751
I can explain at least parts of it, hopefully this will help in understanding what is going on...
what is the ActorRef here?
This is a reference to the actor that was just created. This is an indirect reference, but uniquely identifies the actor instance and can be used to send messages to the actor. See Actor References, Paths and Addresses.
why is name = "myactor" is used, what does it represent?
It is the logical name given to the actor being created, and is used in the hierarchical path for that actor, starting from the root actor to its children and so on. Actors can be "looked up" using the path using an actor selection.
where does the "MySystem" come from?
"MySystem" is the name given to the ActorSystem that is being created. It is an arbitrary name and can be anything you want to label this actor system.
Props[MyActor], what does it mean?
This creates the properties object used to create and configure the actor being created. To create a Props object it needs to know the class of the actor and any constructor arguments. In this case, since you are not providing any constructor arguments, the default constructor for the actor class will be used. See the Actors link below for more info.
Can anyone give me a brief explanation of this whole actor creation process in Scala and Akka?
The creation process is documented at Actors.
Upvotes: 1