Before diving into a full-blown application, let's look at the different components of the actor framework and how they fit together:
receive
method.val echo1 = system.actorOf(Props[EchoActor])
, echo1
has type ActorRef
. An ActorRef
is a proxy for an actor and is what the rest of the world interacts with: when you send a message, you send it to the ActorRef
, not to the actor directly. In fact, you can never obtain a handle to an actor directly in Akka. An actor can obtain an ActorRef
for itself using the .self
method.context
attribute through which you can access methods to create or access other actors and find information about the outside world. We have already seen how to create new actors with context.actorOf(props)
. We can also obtain a reference to an actor's parent through context.parent
. An actor can also stop another actor with context.stop(actorRef)
, where actorRef
is a reference to the actor that we want to stop.context.dispatcher
. Dispatchers implement the ExecutionContext
interface so they can be used to run futures.