Slide 1

Slide 1 text

on Java! actor, persistence! ! Alexey Novakov (Dev Meetup at 360T)!

Slide 2

Slide 2 text

What is Actor Model?! http://blog.scottlogic.com/rdoyle/assets/ActorModel.png! •  Founded in 1973, Carl Hewitt! •  “One Actor is no Actor”! they comes as system! •  Single-threaded! •  Encapsulates states and behavior! •  Unit of Computation!

Slide 3

Slide 3 text

Akka actor elements! •  ActorSystem - group of actors with common configuration; entry point for creating or looking up actors! •  ActorRef - immutable and serializable handle to an actor! •  Props - configuration object to create an Actor! •  ActorPath - unique path according to Actors tree!

Slide 4

Slide 4 text

Sample App! 1.  Generate Stock Exchange Order! 2.  Send it to OrderProcessor actor! 3.  Generate order id by another Actor and reply! 4.  Log prepared order in database by one more actor! - Generate random fail to trigger redelivery!

Slide 5

Slide 5 text

Step 1! Client App! Order Gateway! Order Processor! Actor! OrderId Generator Actor! Place N orders concurrently ! NewOrder! async call!

Slide 6

Slide 6 text

Step 2! Client App! Order Gateway! Order Processor! Actor! OrderId Generator Actor! OrderLog! Actor! Place N orders concurrently ! NewOrder! async call! Dao! MyBatis! DB!

Slide 7

Slide 7 text

Step 3! Client App! Order Gateway! Order Processor! Actor! OrderId Generator Actor! …..! …. Actor N! OrderLog! Actor! Place N orders concurrently ! NewOrder! async call! group! Dao! MyBatis! DB!

Slide 8

Slide 8 text

Step 3! Client App! Order Gateway! Order Processor! Actor! OrderId Generator Actor! …..! …. Actor N! OrderLog! Actor! Place N orders concurrently ! NewOrder! async call! group! Dao! MyBatis! DB!

Slide 9

Slide 9 text

Akka-Persistence! •  Based on “Event-Sourcing”: Command, Events! •  Pluggable journal and snapshot storage (LevelDB, Cassandra, MongoDB, others)! •  Can recover starting from giving sequence_id! •  Guarantee: no new command processed between “persist” and call of “handler”! "com.typesafe.akka" %% "akka-persistence" % "2.4.4"! "org.iq80.leveldb" % "leveldb" % “0.7"! "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8"!

Slide 10

Slide 10 text

Summary! •  Actor incapsulates state and has mailbox (queue)! •  Class UntypedActor is a regular Actor on Java API! •  Methods:! •  tell(), ask()! •  self(), sender()! •  context() - select/create more actors, change state!

Slide 11

Slide 11 text

Why Actors, Akka! •  Highly-scalable! •  Loosely coupled! •  Asynchronous, lock-free! •  Routing, persistence, monitoring is in Akka OTB!! By design!

Slide 12

Slide 12 text

Thank you!! Questions?! Twitter: @alexey_novakov ! ! Web: https://medium.com/se-notes-by-alexey-novakov!