The tell target, also presented as ! , - send a message to the actor. Because participants interact through messaging, tell is the mechanism used to support the transmission of this message. It is asynchronous with the caller, so that as soon as the caller calls tell , they are separated from receiving and processing this message by the instance of the target actor. In this particular example, the code uses the tell command to force the greeter activist to update his internal state. Since this interaction does not lead to any kind of response (the receiving entity does not send the message back to the sender in response to this request), tell enough here.
To get a greeting from a greeting, the interaction is a little different. In this interaction, the sender expects a response message. This type of request / response interaction can be transmitted through ask (i.e. ? ), In which the caller receives Future back, which will be completed when the recipient answers, but ask was not used here. In this example, the encoder received request / response semantics, using instead Inbox , which can act like an actor and eliminates the need for futures. Inbox should look like an ActorRef recipient, allowing it to redirect the response to it with the following line:
sender ! Greeting(greeting)
The sender() method returns the ActorRef the one sent in the processed message. Inbox should be able to present itself as an ActorRef for this. But, as I said earlier, you could also use ask here to make request / response interaction work. I think this is just a matter of choice. The bottom line is that tell used to model the interaction with fire and forgetting, and a mailbox (or another actor or ask ) can be used when request / response semantics are required.
cmbaxter
source share