Top Banner
Globus Scala Laboratory. Iteration #3
12

Scala laboratory: Globus. iteration #3

Jul 15, 2015

Download

Education

Vasil Remeniuk
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scala laboratory: Globus. iteration #3

GlobusScala Laboratory. Iteration #3

Page 2: Scala laboratory: Globus. 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

Page 3: Scala laboratory: Globus. iteration #3

Actor’s concept

● invented in 70th● popularized in 80th in Erlang (OTP

Framework)

Page 4: Scala laboratory: Globus. iteration #3

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

Actor-based systems

Key concepts:● actor● supervisor● dispatcher

Page 6: Scala laboratory: Globus. iteration #3

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

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

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

Supervisors in Akka, II

● when child dies, supervisor receives Terminated(`child`)

Page 10: Scala laboratory: Globus. iteration #3

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

Dispatchers

● provide “resources” for actors to process the message○ Dispatcher○ PinnedDispatcher○ BalancingDispatcher○ CallingThreadDispatcher