Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Akka Finite State Machine


Published on

In Actors system, we can change State or Behaviors during runtime in actors. There are multiple ways for changing behaviors like conditional based and Hotswap but Finite State Machine(FSM) is the cleanest way. If we have finite number of state in our system then FSM is the good practice.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Akka Finite State Machine

  1. 1. By: Harmeet Singh (Taara) Software Consultant
  2. 2. Agenda 1. Actor Model/Akka (Brief) . 2. Finite State Machine (FSM) 3. Demo. 4. Leftover: The things we didn’t cover
  3. 3. ActorModel:Fundamentals ➔ All Computations is performed within Actor. ➔ Actors can communicate only through messages. NOTE: Modeling a software this allows you to deal with state in an atomic way, isolated way which is core principal of actor model.
  4. 4. ActorModel:Fundamentals ➔ In response to a message, an actors can: – Change its State or Behavior – Send message to other actors. – Create a finite number of child's
  5. 5. ActorModel:Fundamentals -Actors can change their State or Behavior ➔ Each behavior in the system can represent a state, and the actor can move from one state to the next when its receives a message. There are few mechanism we can use to change behavior in the face of different states: – Conditional Based on an Actor State. – Hotswat: become() and unbecome(). – Finite State Machine (FSM).
  6. 6. FiniteStateMachine(FSM): -Actors can change their State or Behavior If we are in state S and the event E occurs, we should perform the actions A and make a transition to the state S'. State(S) x Event(E) -> Actions (A), State(S')
  7. 7. Finite State Machine (FSM) ➔ Common language independent modeling technique. ➔ FSM is defined by a number of states and the different triggers for all possible transitions. ➔ Transitions are only happen when the machine is trigger by an event. ➔ Event in an Akka FSM are the messages that actor received.
  8. 8. FiniteStateMachine(FSM): -Visualize FSM
  9. 9. FiniteStateMachine(FSM) –Case Study: Inventory System
  10. 10. FiniteStateMachine(FSM) Case Study: Inventory System Akka-FSM
  11. 11. FiniteStateMachine(FSM) -User Cases ➔ Change actors behaviors according to state. ➔ Perform transitions during actor state change. ➔ Finite number of states. ➔ Model pure actor model using DDD.
  12. 12. Leftover:Thethingswedidn’tcover ➔ Shared state with Agents. ➔ Akka persistence. ➔ Actor Model with DDD (Domain Driven Design). ➔ Akka best Practices.
  13. 13. References: ➔ Applied Akka Patterns By Michael Nash and Wade Waldron. ➔ Learning Akka By Jason Goodwin. ➔ Akka in Action By Raymond Roestenburg (Author) , Rob Bakker (Author) and Rob W