Akka

Writing 'SCALA' ble & concurrent code

CHENSE meetup , Aug 24 2013

Agenda

  • What is a concurrent system?
  • Paradigm
  • AKKA / Actors
  • My First Akka Code & Code walk through
  • Where & How could I use Akka?
  • Q&A

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"

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

Example - "Gopher's Burning Problem" w/o concurrency

Example - Helping Gophers with concurrency

Note : Multiple Gophers => Multicore CPU

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)

Actors <=> Akka

  • lightweight objects which handle message via case classes in Scala
  • use pattern matching to receive msgs
  • async in nature

Code Kata - My First Actor

							
	class Greeter extends Actor {
	  var greeting = ""
	  def receive = {
	    case WhoToGreet(who) => {
	      greeting = s"hello, $who"
	      println(greeting)
	    }
	  }
	}
							
						

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()
}
						

Let's get Real !!!

Where & How could I use Akka ?

  • concurrent applications
  • modeling concurrency
  • clustered message processing

Q & A

Session Where abouts

Source :- https://github.com/prassee/hello-akka

Chense G+ page https://plus.google.com/communities/100102886005161141056

 

-> Thanks <-