Download - Scala laboratory: Globus. iteration #3
![Page 1: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/1.jpg)
GlobusScala Laboratory. Iteration #3
![Page 2: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/2.jpg)
Goals of the iteration● change server-side of Globus Project to use Actors
○ if you already have layer of services, they can be transformed into actors
○ if you don’t have services, refactor the the code
![Page 3: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/3.jpg)
Actor’s concept
● invented in 70th● popularized in 80th in Erlang (OTP
Framework)
![Page 4: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/4.jpg)
Why Actors?
● straightforward concurrency● simple design● easy to scale to multiple nodes
○ location transparency● toolkit for building fault-tolerant systems
![Page 5: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/5.jpg)
Actor-based systems
Key concepts:● actor● supervisor● dispatcher
![Page 6: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/6.jpg)
Actors in Akka1. class MyActor extends Actor {
2. val log = Logging(context.system, this)
3. def receive = {
4. case Ping(message) => log.info(message)
5. }
6. }
![Page 7: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/7.jpg)
Supervisors
● “when someone dies, others will notice”, Joe Armstrong
● when error occurs in an actor, it dies● 2 actors may be linked● when 1 actor dies, another dies as well
○ or, it may handle the error (supervise another actor)
![Page 8: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/8.jpg)
Supervisors in Akka1. class FirstActor extends Actor {
2. val child = context.actorOf(Props[MyActor], name =
"myChild")
3. // plus some behavior ...
4. }
![Page 9: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/9.jpg)
Supervisors in Akka, II
● when child dies, supervisor receives Terminated(`child`)
![Page 10: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/10.jpg)
Supervisors: real-world example
● see http://www.slideshare.net/remeniuk/a-million-bots-cant-be-wrong (slides 10-19)
![Page 11: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/11.jpg)
Dispatchers
● provide “resources” for actors to process the message○ Dispatcher○ PinnedDispatcher○ BalancingDispatcher○ CallingThreadDispatcher
![Page 12: Scala laboratory: Globus. iteration #3](https://reader034.vdocuments.net/reader034/viewer/2022042716/55a68dbc1a28abb27d8b4761/html5/thumbnails/12.jpg)
Dispatchers: real-world example
● http://www.slideshare.net/remeniuk/a-million-bots-cant-be-wrong (slides 35-42)