Upload
softwaremill
View
164
Download
0
Embed Size (px)
Citation preview
An Introduction to Akka
Mikołaj Koziarkiewicz
Akka - what is it? 1/2
a platform,
"for building highly concurrent, distributed, and resilient message-drivenapplications on the JVM."[1],
based on the actor model.
Akka - what is it? 2/2
platform has a lot of specialized extensions
all based on the actor core
goal of the presentation:
explain the core
Actor model - what is it?
actor: unit of computation
actors build actor systems
quite "old" (1973).[2]
Anatomy of an Akka Actor - intro 1/2
class MyActor extends Actor { def receive = { case Something => //... }}
Anatomy of an Akka Actor - intro 2/2
My first Akka Actor™
class HaiActor extends Actor { def receive: Receive = { case target: ActorRef => target ! "Hello!" case "Hello!" => sender ! "OHAI" case "OHAI" => println(s"$self: got OHAI from $sender") }}
Where:
type Receive = PartialFunction[Any, Unit]
My first Akka Actor™ - example
Anatomy of an Akka Actor - hierarchy
Akka actor model - lifecycle & hierarchy
Purpose:
division of labor
supervision:
each actor has lifecycle
special hooks - preStart, preRestart, postStop
allow for e.g. self-init
"parent" controls how it reacts to failure
Hierarchy - example
Akka - guarantees
an actor processes one message at a time,
a message will be delivered at most 1 times,
messages are ordered by sender
Guarantee takeaways
don’t pass mutable state,
use services to ensure send:
contex.scheduler
persistence
Testing
Akka Testkit
Features:
can run special 1-thread dispatcher
asserts for getting msgs
TestProbe
Remoting
Simple remoting:
e.g. "akka.tcp://[email protected]:1337/user/actorName"
remote creation as well
Talking to actor system
Custom:
ask pattern
ask(actoRef, request)(timeout): Future
Many others (also builtin)
Summary
Akka - actor model on the JVM
alternative way to handle
concurrency
distribution
declared guarantees
make reasoning easier
THANK YOU!
The End
Doc link:
http://doc.akka.io/docs/akka/current/scala.html
Bibliography
http://akka.io , retrieved 2015-04-20
https://en.wikipedia.org/wiki/History_of_the_Actor_model , retrieved2015-04-12