Your SlideShare is downloading. ×
0
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Akka knolx
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Akka knolx

2,180

Published on

KnolX session by Meetu Maltiar on new features in Akka 2.0. …

KnolX session by Meetu Maltiar on new features in Akka 2.0.

Friday is KnolX day @Knoldus

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,180
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
23
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2.0 Reloaded Meetu MaltiarEmail: meetu@knoldus.com Twitter:@meetumaltiar
  • 2. Akka 2.0Akka name comes from Sami mythology is actually name of a goddess of wisdom and beauty. Akka incidentally means sister in Telugu!!
  • 3. The ProblemIt is way too hard to build => correct highly concurrent systems => truly scalable systems => self-healing, fault-tolerant systems
  • 4. What is Akka?Right abstraction with actors for concurrent, fault-tolerantand scalable applicationsFor Fault-Tolerance uses “let it crash” modelAbstraction for transparent distribution for load
  • 5. Introducing ActorsActor is an entity encapsulating behavior, state and amailbox to receive messagesFor a message received by Actor a thread is allocated to itThen Actors behavior is applied to the message andpotentially some state is changed or messages is passed toother Actors
  • 6. Introducing Actors..There is elasticity between message processing and additionof new messages. New messages can be added while actorexecution is happening.When processing of messages is completed thread isdeallocated from the actor. It can be reallocated a thread ata later time
  • 7. Create Applicationimport akka.actor.ActorSystemval system =ActorSystem("firstApp")
  • 8. My First Actorimport akka.actor.{ Actor, Props }class MyFirstActor extends Actor { def receive = { case msg => println("Hello!!") }}
  • 9. Create Actorsimport akka.actor.{ ActorSystem, Props }val system = ActorSystem("firstApp")val myFirstActor =system.actorOf(Props[MyFirstActor]) MyFirstActor is an ActorRef Create a top level actor
  • 10. Stop Actorssystem stop myFirstActorAlso stops all actors in hierarchy
  • 11. Send: !myFirstActor ! “Hello” fire-forget
  • 12. Ask: ?import akka.pattern.askimplicit val timeout = Timeout(50000 milliseconds)val future = myActor ? "hello"Await.result(future, timeout.duration).asInstanceOf[Int] Returns a Future[Any]
  • 13. Replyimport akka.actor.Actorclass LongWorkingActor extends Actor { def receive = { case number: Int => sender ! (“Hi I received ” + number) }}
  • 14. RoutersRoundRobinRandomSmallestMailBoxBroadCastScatterGaherFirstCompleted
  • 15. Routers...val router =system.actorOf(Props[RouterWorkerActor].withRouter(RoundRobinRouter(nrOfInstances = 5)))
  • 16. Let It CrashFault Tolerance
  • 17. Actor Pathval actorRef =system.actorFor("akka://actorPathApp/user/parent/child")val parent = context.actorFor("..")val sibling = context.actorFor("../sibling")val refPath = actorRef.path
  • 18. Supervisionclass Supervisor extends Actor { override val supervisorStrategy =OneForOneStrategy(maxNrOfRetries = 10,withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }}
  • 19. Manage Failureclass FaultTolerantService extends Actor { def receive = { case msg => println(msg) } override def preRestart(reason: Throwable, message: Option[Any]) = { // clean up before restart } override def postRestart(reason: Throwable) = { // init after restart }}
  • 20. Code Sampleshttps://github.com/meetumaltiar/AkkaKnolX
  • 21. ReferencesViktor Klang talk on Akka 2.0 at NE Scala symposiumAkka website akka.io

×