Date post: | 16-Apr-2017 |
Category: |
Engineering |
Upload: | johan-andren |
View: | 6,844 times |
Download: | 6 times |
Introduction to Akka Actors
with Java 8
Mememememememememe
Instead of more Ghz more cores
source: http://queue.acm.org/detail.cfm?id=2181798
Another thing that has changed
Build powerful concurrent & distributed applications more easily.
Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM
”The actor model in computer science is a mathematical model of concurrent computation that treats actors as the universal primitives of concurrent computation. ”
Wikipedia
The Actor Model
An Actor
and acts on them by: • Sending messages • Changing its state • Changing its behavior • Creating more actors
receives messages
The Actor hierarchy/user
system.actorOf(props, ”my-actor”)
/user/my-actor
getContext() .actorOf(…, ”my-child”)
/user/my-actor/my-child
Supervision/user
/user/my-actor
🌋
Actor Lifecycle
actorOf()
New instance -
restarted
restart
resume
stop
ActorRef
Dispatch (Actor Execution)Actor-a
Actor-b
Thread 1
Thread 2
b
b
ba a
a
Time
BlockingActor-a
Actor-b
Thread 1
Thread 2
b b
a
Time
a
Actor-c
Dos and don’tsDon’t: Put every actor under /userSeparate parts using supervisors so they can fail independently Do: Isolate blocking Put blocking logic on its own thread based dispatcher Don’t: Write all your logic inside your actorsMake what is possible ”regular” OO logic that you can set up and unit test synchronously
Do: Make all messages immutable Or else there will be concurrency/visibility problems
Do: Put asynchronous boundaries where it makes sense Three tier where each tier is an actor is probably not that useful
What more is there?
Akka Cluster
Akka Streams
and cluster tools
async & back-pressured
Get startedLearn more - the docs: http://akka.io/docs
Get help: gitter channel: https://gitter.im/akka/akka mailing list: https://groups.google.com/forum/#!forum/akka-user
Project with samples: https://github.com/johanandren/akka-actor-java8-webinar