Just reading through Akka samples, cant't understand how is self.reply
defined? As far as I can see, self reply
is used inside receive
blocks to reply to a message. But as far as reply
is a method of self
, then self
is what?
PS: BTW, may you recommend a good quickstart article about Akka basics and remote actors with Scala - I'd appreciate if you could post a link as a comment here. Right now I am reading this.
ActorRefFactory, an interface which is implemented by ActorSystem and akka. actor. ActorContext. This means actors can be created top-level in the ActorSystem or as children of an existing actor, but only from within that actor. ActorRefs can be freely shared among actors by message passing.
The actor context - the view of the actor cell from the actor. Exposes contextual information for the actor and the current message. There are several possibilities for creating actors (see Props for details on props ): // Java or Scala context. actorOf(props, "name") context.
Interacting with an Actor in Akka is done through an ActorRef[T] where T is the type of messages the actor accepts, also known as the “protocol”. This ensures that only the right kind of messages can be sent to an actor and also that no one else but the Actor itself can access the Actor instance internals.
self
is a reference to the ActorRef instance that contains that actor.
When you create a new actor in Akka, the actorOf[class]
method returns an instance of ActorRef, not of your actual Actor implementation, the actor itself is hidden. This ActorRef is what you use to interact with the Actor. So the self
can be used by the actor itself to get this reference.
For example, if your actor wanted to send a message to itself, it would do
self ! Message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With