introduction to akka actors with java 8
TRANSCRIPT
![Page 1: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/1.jpg)
Introduction to Akka Actors
with Java 8
![Page 2: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/2.jpg)
Mememememememememe
![Page 3: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/3.jpg)
Instead of more Ghz more cores
source: http://queue.acm.org/detail.cfm?id=2181798
![Page 4: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/4.jpg)
Another thing that has changed
![Page 5: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/5.jpg)
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
![Page 6: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/6.jpg)
”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
![Page 7: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/7.jpg)
An Actor
and acts on them by: • Sending messages • Changing its state • Changing its behavior • Creating more actors
receives messages
![Page 8: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/8.jpg)
The Actor hierarchy/user
system.actorOf(props, ”my-actor”)
/user/my-actor
getContext() .actorOf(…, ”my-child”)
/user/my-actor/my-child
![Page 9: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/9.jpg)
Supervision/user
/user/my-actor
🌋
![Page 10: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/10.jpg)
Actor Lifecycle
actorOf()
New instance -
restarted
restart
resume
stop
ActorRef
![Page 11: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/11.jpg)
Dispatch (Actor Execution)Actor-a
Actor-b
Thread 1
Thread 2
b
b
ba a
a
Time
![Page 12: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/12.jpg)
BlockingActor-a
Actor-b
Thread 1
Thread 2
b b
a
Time
a
Actor-c
![Page 13: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/14.jpg)
What more is there?
Akka Cluster
Akka Streams
and cluster tools
async & back-pressured
![Page 15: Introduction to akka actors with java 8](https://reader031.vdocuments.mx/reader031/viewer/2022021507/586fdb981a28ab18428b61a7/html5/thumbnails/15.jpg)
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