The document discusses a meetup about writing Scala and concurrent code using Akka. It provides an overview of concurrent systems and actors, describes Akka and how it uses actors to handle concurrency through message passing. It includes an example of "Gopher's burning problem" to illustrate concurrency and walks through a code example of creating a greeter actor in Akka. It also discusses where Akka could be used, such as for concurrent applications, modeling concurrency, and clustered message processing.
2. AGENDA
What is a concurrent system?
Paradigm
AKKA / Actors
My First Akka Code & Code walk through
Where & How could I use Akka?
Q&A
3. WHAT IS A CONCURRENT
SYSTEM?
"Concurrency solves the problem of having
scarce CPU resources and many tasks. So,
you create threads or independent paths
of execution through code in order to
share time on the scarce resource"
4. WHAT IS A CONCURRENT
SYSTEM ? (CONTD.)
capable of doing as many tasks but only one task at a time
like our mind - human mind capability is infinite but we can do at most one task at a time
handle thread lock and manage resources very efficiently
great for writing scalable application
6. EXAMPLE - HELPING GOPHERS WITH CONCURRENCY
Note : Multiple Gophers => Multicore CPU
7. PARADIGM
actor - a concurrent abstraction much like our human
mind
actors over threads to handle concurrency
communicate through message passing (async/ sync)
let actors decide what task to pick up at any instant of
time (take a deep breath)
8. ACTORS <=> AKKA
lightweight objects which handle message via case
classes in Scala
use pattern matching to receive msgs
async in nature
9. CODE KATA - MY FIRST
ACTOR
class Greeter extends Actor {
var greeting = ""
def receive = {
case WhoToGreet(who) => {
greeting = s"hello, $who"
println(greeting)
}
}
}
10. CODE KATA - WRITING
AKKA CLIENT
object HelloAkkaScala extends App {
// Create the 'helloakka' actor system
val system = ActorSystem("helloakka")
// Create the 'greeter' actor
val greeter = system.actorOf(Props[Greeter], "greeter")
greeter.!(WhoToGreet("first message"))
system.shutdown()
}