add stateName and stateData accessors to FSM

This commit is contained in:
Roland 2011-05-29 20:53:38 +02:00
parent 1970b96ae5
commit 6b6ec0df72
2 changed files with 14 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import akka.testkit._
import FSM._
import akka.util.Duration
import akka.util.duration._
import akka.event._
object FSMActorSpec {
@ -57,8 +58,9 @@ object FSMActorSpec {
}
whenUnhandled {
case Event(_, stateData) {
case Ev(msg) {
unhandledLatch.open
EventHandler.info(this, "unhandled event " + msg + " in state " + stateName + " with data " + stateData)
stay
}
}

View file

@ -306,7 +306,7 @@ trait FSM[S, D] extends ListenerManagement {
* function literal. To be used with onTransition.
*/
implicit protected final def total2pf(transitionHandler: (S, S) Unit) =
new PartialFunction[(S, S), Unit] {
new TransitionHandler {
def isDefinedAt(in: (S, S)) = true
def apply(in: (S, S)) { transitionHandler(in._1, in._2) }
}
@ -334,6 +334,16 @@ trait FSM[S, D] extends ListenerManagement {
}
/**
* Return current state name (i.e. object of type S)
*/
def stateName: S = currentState.stateName
/**
* Return current state data (i.e. object of type D)
*/
def stateData: D = currentState.stateData
/*
* ****************************************************************
* PRIVATE IMPLEMENTATION DETAILS
* ****************************************************************