Skip to content

Instantly share code, notes, and snippets.

@momania
Created November 15, 2010 07:09
Show Gist options
  • Save momania/700121 to your computer and use it in GitHub Desktop.
Save momania/700121 to your computer and use it in GitHub Desktop.
A to B to C
package actor.actor
import akka.actor.{Actor, FSM}
import java.util.concurrent.TimeUnit
sealed trait ExampleState
case object A extends ExampleState
case object B extends ExampleState
case object C extends ExampleState
case object Move
class ABC extends Actor with FSM[ExampleState,Unit] {
when(A) {
case Event(Move, _) =>
log.info("Go to B and move on after 5 seconds")
goto(B) until 5000
}
when(B) {
case Event(StateTimeout, _) =>
log.info("Moving to C")
goto(C)
}
when(C) {
case Event(Move, _) =>
log.info("Stopping")
stop
}
startWith(A, Unit)
}
object ABC {
def main(args: Array[String]) {
val abc = Actor.actorOf[ABC].start
abc ! Move
TimeUnit.SECONDS.sleep(6)
abc ! Move
System.exit(0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment