Last active
May 26, 2021 23:11
-
-
Save michalkowol/1a833a2f7fc58bd3da1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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