Created
November 15, 2010 07:09
-
-
Save momania/700121 to your computer and use it in GitHub Desktop.
A to B to C
This file contains 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 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