FSM

startWith(LookingAround, EmptyShoppingCart) when(LookingAround) { case Event(AddItem(item), _) ⇒ goto(Shopping) applying ItemAdded(item) forMax (1 seconds) case Event(GetCurrentCart, data) ⇒ stay replying data } when(Shopping) { case Event(AddItem(item), _) ⇒ stay applying ItemAdded(item) forMax (1 seconds) case Event(Buy, _) ⇒ goto(Paid) applying OrderExecuted andThen { case NonEmptyShoppingCart(items) ⇒ reportActor ! PurchaseWasMade(items) saveStateSnapshot() case EmptyShoppingCart ⇒ saveStateSnapshot() } case Event(Leave, _) ⇒ stop applying OrderDiscarded andThen { case _ ⇒ reportActor ! ShoppingCardDiscarded saveStateSnapshot() } case Event(GetCurrentCart, data) ⇒ stay replying data case Event(StateTimeout, _) ⇒ goto(Inactive) forMax (2 seconds) } when(Inactive) { case Event(AddItem(item), _) ⇒ goto(Shopping) applying ItemAdded(item) forMax (1 seconds) case Event(StateTimeout, _) ⇒ stop applying OrderDiscarded andThen { case _ ⇒ reportActor ! ShoppingCardDiscarded } } when(Paid) { case Event(Leave, _) ⇒ stop() case Event(GetCurrentCart, data) ⇒ stay replying data }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.