Skip to content

Instantly share code, notes, and snippets.

@michalkowol
Last active May 26, 2021 23:11
Show Gist options
  • Save michalkowol/1a833a2f7fc58bd3da1e to your computer and use it in GitHub Desktop.
Save michalkowol/1a833a2f7fc58bd3da1e to your computer and use it in GitHub Desktop.
package com.michalkowol.authapi.core.actor.sitecontent
import akka.actor.{ActorRef, FSM}
import com.paypal.cascade.akka.actor.ServiceActor
object FSMExample {
sealed trait State
object State {
case object State1 extends State
case object State2 extends State
}
case class Data(value: Int = 0)
}
class FSMExample(origin: ActorRef) extends ServiceActor with FSM[FSMExample.State, FSMExample.Data] {
import FSMExample._
startWith(State.State1, new Data)
when(State.State1) {
case Event(msg: Int, Data(value)) =>
goto(State.State2) using Data(value + msg)
}
when(State.State2) {
case Event(msg: Int, Data(value)) =>
origin ! value + 2 * msg
stop()
}
onTransition {
case x -> y => log.debug("Transitioning from state {} into state {}", x, y)
}
initialize()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment