Actors • Akka Documentation
This is obviously based on a combination of "thread based" and "event based programming". This raises for me the question what is the difference between "thread based" and "event based" and how to combine it or how it is combined in "Scala Actors"? This question has been asked before and already has an answer.
If those answers do not fully address your question, please ask a new question. Learn more. First 10 Free. Asked 4 months ago. Viewed 54 times.
- The Scala Actors API.
- Navigation menu.
- If you’re still using Synchronized, you should try Akka Actor instead — here’s why.
- Village Midwife, Blushing Bride?
This question already has an answer here: How are the multiple Actors implementation in Scala different? HelloWorld92 HelloWorld92 1 1 1 bronze badge. May 7 at This question has been asked before and already has an answer.
- Sensors and Transducers: Characteristics, Applications, Instrumentation, Interfacing!
- Concurrency made easy with Scala and Akka.
- Stay ahead with the world's most comprehensive technology and business learning platform..
- Hawaiian UFO Aliens.
- Communicative Engagement and Social Liberation: Justice Will Be Made!
- You may also like.
Scala Actors were deprecated 5 years ago! However, for this post we're going to focus on the receive method. This method will fetch messages from the mailbox and run it through our pattern matching to figure out what to do.
Actors in Scala
Next we add the new client to our client list. The last thing we do is to make the server start monitoring the client actor by calling watch. Doing this, the server actor will receive a Terminated message if the client actor is terminated.
Pretty cool right? This case doesn't contain anything special. It just finds the username of the sender based on the ActorRef and then sends a NewMsg to all the clients connected to the server.
Using Akka Typed
Since we registered for Terminated messages from clients when they connected, we need to handle them. In this case the server simply notifies the other clients that a client disconnected, then removes the client from the client list. There isn't much actor related to tell that hasn't been told in the server part. However, there are a few things worth mentioning. On Disconnect , the client sends a PoisonPill message to itself to trigger the termination.
A Terminated message will then be published to DeathWatch , which will then notify our server actor. This is the entry point for creating our actors. Actors created under the same ActorSystem share several configurations and form a hierarchical group. Creating an ActorSystem is quite expensive, so you shouldn't create them without having a good reason.
- Life and death : philosophical essays in biomedical ethics!
- Scala Cookbook by Alvin Alexander.
- College algebra and calculus : an applied approach.
To create the actor, we use ActorSystem. Props is an ActorRef config object for creating new actors. That's it for this quick introduction on creating actors using Scala and Akka.