Globus Scala Laboratory. Iteration #3
GlobusScala Laboratory. Iteration #3
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
Actor’s concept
● invented in 70th● popularized in 80th in Erlang (OTP
Framework)
Why Actors?
● straightforward concurrency● simple design● easy to scale to multiple nodes
○ location transparency● toolkit for building fault-tolerant systems
Actor-based systems
Key concepts:● actor● supervisor● dispatcher
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. }
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)
Supervisors in Akka1. class FirstActor extends Actor {
2. val child = context.actorOf(Props[MyActor], name =
"myChild")
3. // plus some behavior ...
4. }
Supervisors in Akka, II
● when child dies, supervisor receives Terminated(`child`)
Supervisors: real-world example
● see http://www.slideshare.net/remeniuk/a-million-bots-cant-be-wrong (slides 10-19)
Dispatchers
● provide “resources” for actors to process the message○ Dispatcher○ PinnedDispatcher○ BalancingDispatcher○ CallingThreadDispatcher
Dispatchers: real-world example
● http://www.slideshare.net/remeniuk/a-million-bots-cant-be-wrong (slides 35-42)