This sample is an adaptation of
Dining Hakkers.
It illustrates how state and behavior can be managed within
an Actor with two different approaches; using become
and using
the FSM
trait.
The sample also contains an implementation of a simple redelivering actor implemented as a FSM.
Open DiningHakkersOnBecome.scala.
It illustrates how current behavior can be replaced with context.become
.
Note that no var
members are used, instead the state is encoded in the current
behavior and its parameters.
Go to the Run tab, and start the application's main class
sample.become.DiningHakkersOnBecome
.
In the log output you can see the actions of the Hakker
actors.
Read more about become
in
the documentation.
Open DiningHakkersOnFsm.scala.
It illustrates how the states and transitions can be defined with the akka.actor.FSM
trait.
Go to the Run tab, and start the application's main class
sample.fsm.DiningHakkersOnFsm
.
In the log output you can see the actions of the Hakker
actors.
Read more about akka.actor.FSM
in
the documentation.
Open FsmSimpleRedelivery.scala.
It illustrates how you can take care of message redelivery between two or more sides. This implementation is able to process only one message at a time.
Go to the Run tab, and start the application's main class
sample.redelivery.FsmSimpleRedelivery
.
In the log output you can see the actions of the Requester
and the Receiver
actors.