add stateName and stateData accessors to FSM
This commit is contained in:
parent
1970b96ae5
commit
6b6ec0df72
2 changed files with 14 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ import akka.testkit._
|
||||||
import FSM._
|
import FSM._
|
||||||
import akka.util.Duration
|
import akka.util.Duration
|
||||||
import akka.util.duration._
|
import akka.util.duration._
|
||||||
|
import akka.event._
|
||||||
|
|
||||||
object FSMActorSpec {
|
object FSMActorSpec {
|
||||||
|
|
||||||
|
|
@ -57,8 +58,9 @@ object FSMActorSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
whenUnhandled {
|
whenUnhandled {
|
||||||
case Event(_, stateData) ⇒ {
|
case Ev(msg) ⇒ {
|
||||||
unhandledLatch.open
|
unhandledLatch.open
|
||||||
|
EventHandler.info(this, "unhandled event " + msg + " in state " + stateName + " with data " + stateData)
|
||||||
stay
|
stay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ trait FSM[S, D] extends ListenerManagement {
|
||||||
* function literal. To be used with onTransition.
|
* function literal. To be used with onTransition.
|
||||||
*/
|
*/
|
||||||
implicit protected final def total2pf(transitionHandler: (S, S) ⇒ Unit) =
|
implicit protected final def total2pf(transitionHandler: (S, S) ⇒ Unit) =
|
||||||
new PartialFunction[(S, S), Unit] {
|
new TransitionHandler {
|
||||||
def isDefinedAt(in: (S, S)) = true
|
def isDefinedAt(in: (S, S)) = true
|
||||||
def apply(in: (S, S)) { transitionHandler(in._1, in._2) }
|
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
|
* PRIVATE IMPLEMENTATION DETAILS
|
||||||
* ****************************************************************
|
* ****************************************************************
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue