Merge branch 'master' of github.com:jboner/akka
This commit is contained in:
commit
5c3c24bc58
2 changed files with 32 additions and 0 deletions
|
|
@ -29,6 +29,19 @@ object FSMTransitionSpec {
|
|||
override def preRestart(reason: Throwable, msg: Option[Any]) { target ! "restarted" }
|
||||
}
|
||||
|
||||
class OtherFSM(target: ActorRef) extends Actor with FSM[Int, Int] {
|
||||
startWith(0, 0)
|
||||
when(0) {
|
||||
case Ev("tick") ⇒ goto(1) using (1)
|
||||
}
|
||||
when(1) {
|
||||
case Ev(_) ⇒ stay
|
||||
}
|
||||
onTransition {
|
||||
case 0 -> 1 ⇒ target ! ((stateData, nextStateData))
|
||||
}
|
||||
}
|
||||
|
||||
class Forwarder(target: ActorRef) extends Actor {
|
||||
def receive = { case x ⇒ target ! x }
|
||||
}
|
||||
|
|
@ -72,4 +85,16 @@ class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
|
|||
}
|
||||
}
|
||||
|
||||
"A FSM" must {
|
||||
|
||||
"make previous and next state data available in onTransition" in {
|
||||
val fsm = system.actorOf(new OtherFSM(testActor))
|
||||
within(300 millis) {
|
||||
fsm ! "tick"
|
||||
expectMsg((0, 1))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -382,6 +382,11 @@ trait FSM[S, D] extends ListenerManagement {
|
|||
*/
|
||||
protected[akka] def stateData: D = currentState.stateData
|
||||
|
||||
/**
|
||||
* Return next state data (available in onTransition handlers)
|
||||
*/
|
||||
protected[akka] def nextStateData = nextState.stateData
|
||||
|
||||
/*
|
||||
* ****************************************************************
|
||||
* PRIVATE IMPLEMENTATION DETAILS
|
||||
|
|
@ -393,6 +398,7 @@ trait FSM[S, D] extends ListenerManagement {
|
|||
*/
|
||||
private var currentState: State = _
|
||||
private var timeoutFuture: Option[Cancellable] = None
|
||||
private var nextState: State = _
|
||||
private var generation: Long = 0L
|
||||
|
||||
/*
|
||||
|
|
@ -515,6 +521,7 @@ trait FSM[S, D] extends ListenerManagement {
|
|||
} else {
|
||||
nextState.replies.reverse foreach { r ⇒ sender ! r }
|
||||
if (currentState.stateName != nextState.stateName) {
|
||||
this.nextState = nextState
|
||||
handleTransition(currentState.stateName, nextState.stateName)
|
||||
notifyListeners(Transition(self, currentState.stateName, nextState.stateName))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue