On Github edofic / akka-talk
Andraž Bajt / @edofic
I'm a student. Programming in scala for a year. Doing some Akka stuff currently. I'm on twitter and some other networks, I have a blog. How many are familiar with akka?Concurrency: two tasks running
Parallelism: two things running at the same time
Different take on OO
Picture says it all. There are lightweight actors that send messages to eachother. Every actor has a mailbox. I processes one message at a time. Therefore single threaded. EASY to reason about. Can wrap mutable state safely. Can create new actors. Graphs that heal them self. Vending machine is cjust a proxy to another vending machine. And it can repair it.Defining actors
import akka.actor._ case class DoStuff(s: String) class Worker extends Actor { def receive = { case DoStuff(s) => doStuff(s) case msg: String => println(msg) case 42 => sender ! "You'll need a bigger computer for that" } def doStuff(s: String) = ... //some blocking operation }
Usage
import akka.actor._ import akka.pattern.ask val sys = ActorSystem() val worker = sys.actorOf(Props[Worker]) worker ! DoStuff("details") worker ! "hello world" val question: Future[Question] = worker ? 42
import akka.routing.RoundRobin val worker = sys.actorOf( Props[Worker] withRouter RoundRobin(5), "myWorker" )
Exact same code!
akka.actor.deployment { /myWorker { router = random-router nr-of-instances = 17 } }There is also router FromConfig. You can define your own.
Just change the config
See http://akka.io/