Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is `self` in Akka?

Tags:

scala

akka

actor

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.

like image 222
Ivan Avatar asked Nov 02 '11 21:11

Ivan


People also ask

What is ActorRef in Akka?

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.

What is context in Akka?

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.

What is Akka protocol?

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.


1 Answers

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
like image 159
Dan Simon Avatar answered Oct 26 '22 21:10

Dan Simon