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 AbstractFSM
class.
Open DiningHakkersOnBecome.java.
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.
Start the application by typing sbt "runMain sample.become.DiningHakkersOnBecome"
or mvn compile exec:java -Dexec.mainClass="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.java.
It illustrates how the states and transitions can be defined with the akka.actor.AbstractFSM
class.
Start the application by typing sbt "runMain sample.fsm.DiningHakkersOnFsm"
or mvn compile exec:java -Dexec.mainClass="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 DiningHakkersTyped.java.
It illustrates how the behaviors and transitions can be defined with Akka Typed.
Start the application by typing sbt "runMain sample.typed.DiningHakkersTyped"
. In the log output you can see the actions of the Hakker
actors.
Read more about Akka Typed in the documentation.