Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven,...
Transcript of Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven,...
![Page 1: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/1.jpg)
Akka:Simpler Concurrency, Scalability &
Fault-tolerance through Actors
Jonas BonérScalable Solutions
[email protected] : @jboner
Wednesday, February 16, 2011
![Page 2: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/2.jpg)
The problem
It is way too hard to build:1. correct highly concurrent systems
2. truly scalable systems
3. fault-tolerant systems that self-heals
...using “state-of-the-art” tools
Wednesday, February 16, 2011
![Page 3: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/3.jpg)
akkaIntroducing
Wednesday, February 16, 2011
![Page 4: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/4.jpg)
Vision
Simpler
Concurrency
Scalability
Fault-tolerance
Wednesday, February 16, 2011
![Page 5: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/5.jpg)
Vision
...with One single unified
Programming model
Runtime service
Wednesday, February 16, 2011
![Page 6: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/6.jpg)
Manage system overload
Wednesday, February 16, 2011
![Page 7: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/7.jpg)
Scale up & Scale out
Wednesday, February 16, 2011
![Page 8: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/8.jpg)
Replicate and distribute for fault-tolerance
Wednesday, February 16, 2011
![Page 9: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/9.jpg)
Transparent load balancingWednesday, February 16, 2011
![Page 10: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/10.jpg)
Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM
Simpler ConcurrencyEvent-driven Architecture
True ScalabilityFault-tolerance
Transparent RemotingJava & Scala API
Overview
Wednesday, February 16, 2011
![Page 11: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/11.jpg)
CORE SERVICES
ARCHITECTURE
Wednesday, February 16, 2011
![Page 12: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/12.jpg)
ADD-ON MODULES
ARCHITECTURE
Wednesday, February 16, 2011
![Page 13: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/13.jpg)
ARCHITECTURE
CLOUDY AKKA
Wednesday, February 16, 2011
![Page 14: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/14.jpg)
FINANCE
• Stock trend Analysis & Simulation
• Event-driven messaging systems
BETTING & GAMING
• Massive multiplayer online gaming
• High throughput and transactional betting
TELECOM
• Streaming media network gateways
SIMULATION
• 3D simulation engines
E-COMMERCE
• Social media community sites
SOME EXAMPLES:
WHERE IS AKKA USED?
Wednesday, February 16, 2011
![Page 15: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/15.jpg)
What is an Actor?
Wednesday, February 16, 2011
![Page 16: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/16.jpg)
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 17: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/17.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 18: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/18.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 19: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/19.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 20: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/20.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 21: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/21.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 22: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/22.jpg)
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 23: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/23.jpg)
Event-drivenThread
Behavior
State
Actor
Wednesday, February 16, 2011
![Page 24: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/24.jpg)
Akka Actorsone tool in the toolbox
Wednesday, February 16, 2011
![Page 25: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/25.jpg)
Actor Model Benefits• Easier to reason about• Raised abstraction level• Easier to avoid– Race conditions– Deadlocks– Starvation– Live locks
Wednesday, February 16, 2011
![Page 26: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/26.jpg)
case object Tick
class Counter extends Actor { var counter = 0
def receive = { case Tick => counter += 1 println(counter) }}
Actors
Wednesday, February 16, 2011
![Page 27: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/27.jpg)
val counter = actorOf[Counter]
Create Actors
counter is an ActorRef
Wednesday, February 16, 2011
![Page 28: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/28.jpg)
val actor = actorOf(new MyActor(..))
Create Actors
create actor with constructor arguments
Wednesday, February 16, 2011
![Page 29: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/29.jpg)
val counter = actorOf[Counter]counter.start
Start actors
Wednesday, February 16, 2011
![Page 30: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/30.jpg)
val counter = actorOf[Counter].start
Start actors
Wednesday, February 16, 2011
![Page 31: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/31.jpg)
val counter = actorOf[Counter].startcounter.stop
Stop actors
Wednesday, February 16, 2011
![Page 32: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/32.jpg)
class MyActor extends Actor {
override def preStart = { ... // called before ‘start’ }
override def postStop = { ... // called after ‘stop’ }}
life-cycle callbacks
Wednesday, February 16, 2011
![Page 33: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/33.jpg)
counter ! Tick
Send: !
fire-forget
Wednesday, February 16, 2011
![Page 34: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/34.jpg)
val result = (actor !! Message).as[String]
Send: !!
uses Future under the hood (with time-out)
Wednesday, February 16, 2011
![Page 35: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/35.jpg)
// returns a futureval future = actor !!! Messagefuture.awaitval result = future.get
...Futures.awaitOne(List(fut1, fut2, ...))Futures.awaitAll(List(fut1, fut2, ...))
Send: !!!
returns the Future directly
Wednesday, February 16, 2011
![Page 36: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/36.jpg)
Futureval future1, future2, future3 = new DefaultCompletableFuture(1000)
future1.awaitfuture2.onComplete(f => ...)future3.map((f) => ...)
future1.completeWithResult(...) future2.completeWithException(...)future3.completeWith(future2)
Wednesday, February 16, 2011
![Page 37: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/37.jpg)
class SomeActor extends Actor { def receive = { case User(name) => // use reply self.reply(“Hi ” + name) }}
Reply
Wednesday, February 16, 2011
![Page 38: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/38.jpg)
class SomeActor extends Actor { def receive = { case User(name) => // store away the sender // to use later or // somewhere else ... = self.sender }}
Reply
Wednesday, February 16, 2011
![Page 39: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/39.jpg)
class SomeActor extends Actor { def receive = { case User(name) => // store away the sender future // to resolve later or // somewhere else ... = self.senderFuture }}
Reply
Wednesday, February 16, 2011
![Page 40: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/40.jpg)
HotSwap
self become { // new body case NewMessage => ... }
Wednesday, February 16, 2011
![Page 41: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/41.jpg)
HotSwap
actor ! HotSwap { // new body case NewMessage => ... }
Wednesday, February 16, 2011
![Page 42: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/42.jpg)
HotSwap
self.unbecome()
Wednesday, February 16, 2011
![Page 43: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/43.jpg)
val actors = Actor.registry.actors()val actors = Actor.registry.actorsFor[TYPE]val actors = Actor.registry.actorsFor(id)val actor = Actor.registry.actorFor(uuid)Actor.registry.shutdownAll()
ActorRegistry
Wednesday, February 16, 2011
![Page 44: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/44.jpg)
class MyActor extends Actor { self.dispatcher = Dispatchers .newThreadBasedDispatcher(self) ...}
actor.dispatcher = dispatcher // before started
Set dispatcher
Wednesday, February 16, 2011
![Page 45: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/45.jpg)
Let it crash fault-tolerance
Wednesday, February 16, 2011
![Page 46: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/46.jpg)
Stolen from
ErlangWednesday, February 16, 2011
![Page 47: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/47.jpg)
9 nines
Wednesday, February 16, 2011
![Page 48: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/48.jpg)
...let’s take a standard OO application
Wednesday, February 16, 2011
![Page 49: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/49.jpg)
Wednesday, February 16, 2011
![Page 50: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/50.jpg)
Which components have critically important state
and explicit error handling?
Wednesday, February 16, 2011
![Page 51: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/51.jpg)
Wednesday, February 16, 2011
![Page 52: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/52.jpg)
Classification of State• Scratch data• Static data• Supplied at boot time• Supplied by other components
• Dynamic data• Data possible to recompute• Input from other sources; data
that is impossible to recompute
Wednesday, February 16, 2011
![Page 53: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/53.jpg)
Classification of State• Scratch data• Static data• Supplied at boot time• Supplied by other components
• Dynamic data• Data possible to recompute• Input from other sources; data
that is impossible to recompute
Wednesday, February 16, 2011
![Page 54: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/54.jpg)
Classification of State• Scratch data• Static data• Supplied at boot time• Supplied by other components
• Dynamic data• Data possible to recompute• Input from other sources; data
that is impossible to recompute
Must be protected
by any means
Wednesday, February 16, 2011
![Page 55: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/55.jpg)
Fault-tolerant onion-layered Error Kernel
Wednesday, February 16, 2011
![Page 56: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/56.jpg)
An actor-based application with explicit error handling and
critically important state in an
Error Kernel
Wednesday, February 16, 2011
![Page 57: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/57.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 58: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/58.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 59: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/59.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 60: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/60.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 61: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/61.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 62: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/62.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 63: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/63.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 64: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/64.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 65: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/65.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 66: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/66.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 67: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/67.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 68: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/68.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 69: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/69.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 70: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/70.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 71: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/71.jpg)
ErrorKernel
Wednesday, February 16, 2011
![Page 72: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/72.jpg)
Wednesday, February 16, 2011
![Page 73: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/73.jpg)
Wednesday, February 16, 2011
![Page 74: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/74.jpg)
Node 1 Node 2
Wednesday, February 16, 2011
![Page 75: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/75.jpg)
Wednesday, February 16, 2011
![Page 76: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/76.jpg)
Wednesday, February 16, 2011
![Page 77: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/77.jpg)
Node 1 Node 2
Wednesday, February 16, 2011
![Page 78: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/78.jpg)
Node 1 Node 2
Replication
Wednesday, February 16, 2011
![Page 79: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/79.jpg)
AllForOneStrategy( problems, maxNrOfRetries, withinTimeRange)
OneForOneStrategy( problems, maxNrOfRetries, withinTimeRange)
Fault handlers
Wednesday, February 16, 2011
![Page 80: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/80.jpg)
link(actor)unlink(actor)
startLink(actor)spawnLink[MyActor]
Linking
Wednesday, February 16, 2011
![Page 81: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/81.jpg)
class Supervisor extends Actor { faultHandler = OneForOneStrategy( List(classOf[Throwable]) 5, 5000))
def receive = { case Register(actor) => link(actor) }}
Supervision
Wednesday, February 16, 2011
![Page 82: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/82.jpg)
class FaultTolerantService extends Actor { ... override def preRestart(reason: Throwable) = { ... // clean up before restart } override def postRestart(reason: Throwable) = { ... // init after restart }}
Manage failure
Wednesday, February 16, 2011
![Page 83: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/83.jpg)
Supervisor supervisor = Supervisor( SupervisorConfig( AllForOneStrategy(List(classOf[Exception]), 3, 1000), Supervise( actor1, Permanent) :: Supervise( actor2, Temporary) :: Nil ))
Declarative config
Wednesday, February 16, 2011
![Page 84: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/84.jpg)
Remote Actors
Wednesday, February 16, 2011
![Page 85: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/85.jpg)
// use host & port in configActor.remote.start()
Actor.remote.start("localhost", 2552)
Remote Server
Scalable implementation based on NIO (Netty) & Protobuf
Wednesday, February 16, 2011
![Page 86: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/86.jpg)
Two types of
remote actorsClient initiated & managedServer initiated & managed
Wednesday, February 16, 2011
![Page 87: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/87.jpg)
import Actor._
val service = remote.actorOf[MyActor](host, port)
service ! message
Client-managedsupervision works across nodes
Wednesday, February 16, 2011
![Page 88: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/88.jpg)
import Actor._
remote.register(“service:id”, actorOf[MyService])
Server-managedregister and manage actor on server
client gets “dumb” proxy handle
server partWednesday, February 16, 2011
![Page 89: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/89.jpg)
val service = remote.actorFor( “service:id”, “darkstar”, 9999)
service ! message
Server-managed
client part
Wednesday, February 16, 2011
![Page 90: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/90.jpg)
import Actor._
remote.register(actorOf[MyService])remote.registerByUuid(actorOf[MyService])remote.registerPerSession( “service:id”, actorOf[MyService])
remote.unregister(“service:id”) remote.unregister(actorRef)
Server-managed
server partWednesday, February 16, 2011
![Page 91: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/91.jpg)
akka { remote { secure-‐cookie = "050E0A0D0D06010A00000900040D060F0C09060B" server { require-‐cookie = on untrusted-‐mode = on } }}
Remoting Security
Erlang-style secure cookieWednesday, February 16, 2011
![Page 92: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/92.jpg)
Clustered Actors
Wednesday, February 16, 2011
![Page 93: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/93.jpg)
• Subscription-based cluster membership service• Highly available cluster registry for actors• Highly available centralized configuration service• Automatic replication with automatic fail-over
upon node crash• Transparent and user-configurable load-balancing• Transparent adaptive cluster rebalancing• Leader election
Cloudy Akka
Wednesday, February 16, 2011
![Page 94: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/94.jpg)
ZooKeeperZooKeeperZooKeeperEnsemble
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
Wednesday, February 16, 2011
![Page 95: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/95.jpg)
ZooKeeperZooKeeperZooKeeperEnsemble
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
Wednesday, February 16, 2011
![Page 96: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/96.jpg)
ZooKeeperZooKeeperZooKeeperEnsemble
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
Wednesday, February 16, 2011
![Page 97: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/97.jpg)
ZooKeeperZooKeeperZooKeeperEnsemble
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaDashboard
AkkaStatistics
Server
Wednesday, February 16, 2011
![Page 98: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/98.jpg)
ZooKeeperZooKeeperZooKeeperEnsemble
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaCluster Node
AkkaDashboard
AkkaStatistics
Server
Wednesday, February 16, 2011
![Page 99: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/99.jpg)
// Ping Pong messages @serializable sealed trait PingPong case object Ball extends PingPong case object Stop extends PingPong
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 100: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/100.jpg)
@serializable class PingActor extends Actor { var count = 0
def receive = { case Ball => if (count < NrOfPings) { println("-‐-‐-‐-‐>> PING (%s)" format count) count += 1 self reply Ball } else { self.sender.foreach(_ !! Stop) self.stop } } }
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 101: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/101.jpg)
@serializable class PongActor extends Actor { def receive = { case Ball => self reply Ball case Stop => self.stop } }
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 102: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/102.jpg)
Cluster.startLocalCluster()
val localNode = Cluster.newNode(NodeAddress(CLUSTER_NAME, "node0", port = 9991)).start val remoteNodes = Cluster.newNode(NodeAddress(CLUSTER_NAME, "node1", port = 9992)).start :: Cluster.newNode(NodeAddress(CLUSTER_NAME, "node2", port = 9993)).start :: Cluster.newNode(NodeAddress(CLUSTER_NAME, "node3", port = 9994)).start :: Cluster.newNode(NodeAddress(CLUSTER_NAME, "node4", port = 9995)).start :: Nil
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 103: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/103.jpg)
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 104: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/104.jpg)
localNode store (classOf[PingActor])
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 105: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/105.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 106: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/106.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 107: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/107.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 108: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/108.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head val pong = localNode.ref(
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 109: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/109.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head val pong = localNode.ref( actorId = PONG_SERVICE, router = Router.RoundRobin)
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 110: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/110.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head val pong = localNode.ref( actorId = PONG_SERVICE, router = Router.RoundRobin)
implicit val replyTo = Some(pong) // set the reply address
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 111: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/111.jpg)
localNode store (classOf[PingActor]) localNode store (classOf[PongActor], 5)
val ping = localNode.use[PingActor](actorId = PING_SERVICE).head val pong = localNode.ref( actorId = PONG_SERVICE, router = Router.RoundRobin)
implicit val replyTo = Some(pong) // set the reply address ping ! Ball // serve
Example: Clustered Actors
Wednesday, February 16, 2011
![Page 112: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/112.jpg)
Deploy as dependency JAR in WEB-INF/lib etc. Run as stand-alone microkernel OSGi-enabled; drop in any OSGi container (Spring DM server, Karaf etc.)
How to run it?
Wednesday, February 16, 2011
![Page 113: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/113.jpg)
AMQP
Dataflow
Security
...and much much more
HTTP
Guice
OSGiPubSub
JTA
FSM
Persistence
STM
Spring
Camel
Wednesday, February 16, 2011
![Page 114: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/114.jpg)
GroovyJRuby
Use Akka from
JavaScala
Wednesday, February 16, 2011
![Page 116: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/116.jpg)
Get it and learn morehttp://akka.io
Wednesday, February 16, 2011
![Page 117: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/117.jpg)
EOFWednesday, February 16, 2011
![Page 118: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/118.jpg)
Akka Camel
Wednesday, February 16, 2011
![Page 119: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/119.jpg)
class MyConsumer extends Actor with Consumer { def endpointUri = "file:data/input" def receive = { case msg: Message => log.info("received %s" format msg.bodyAs(classOf[String])) }}
Camel: consumer
Wednesday, February 16, 2011
![Page 120: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/120.jpg)
class MyConsumer extends Actor with Consumer { def endpointUri = "jetty:http://0.0.0.0:8877/camel/test" def receive = { case msg: Message => reply("Hello %s" format msg.bodyAs(classOf[String])) }}
Camel: consumer
Wednesday, February 16, 2011
![Page 121: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/121.jpg)
class CometProducer extends Actor with Producer { def endpointUri = "cometd://localhost:8111/test"}
Camel: producer
Wednesday, February 16, 2011
![Page 122: Scalable Solutions - Jfokus€¦ · Akka is the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM Simpler Concurrency Event-driven](https://reader034.fdocuments.in/reader034/viewer/2022042408/5f23075fbca18702c6260b83/html5/thumbnails/122.jpg)
val producer = actorOf[CometProducer].start
val time = "Current time: " + new Dateproducer ! time
Camel: producer
Wednesday, February 16, 2011