By:
Harmeet Singh (Taara)
Software Consultant
Agenda
1. Actor Model/Akka (Brief)
.
2. Finite State Machine (FSM)
3. Demo.
4. Leftover: The things we didn’t cover
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.
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
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).
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')
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.
FiniteStateMachine(FSM):
-Visualize FSM
FiniteStateMachine(FSM)
–Case Study: Inventory System
FiniteStateMachine(FSM)
Case Study: Inventory System
Akka-FSM
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.
Leftover:Thethingswedidn’tcover
âž” Shared state with Agents.
âž” Akka persistence.
âž” Actor Model with DDD (Domain Driven Design).
âž” Akka best Practices.
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

Akka Finite State Machine

Editor's Notes

  • #9 FSM is a DSL that allows you to build more sophisticated, readable state machines than would be possible using the core actor API
  • #10 1.1 FSM is also called state machine. 1.2 FSM is called machine because it can only be one of a finite number of states. 1.3 Changing from one state to another is trigger by an event or condition. 2.1 The common example of FSM is Washing Machine where states are filling the tub, agitation, draining spinning …
  • #11 Note: Exit action can do some cleaning or restore some state, so they don’t embody part of the login of the machine line finally block in try/catch clause.