Hi all,
Suppose that I need to get two user confirmations within StateA so that I can move to StateB. Since user input is gathered from mic, there can be long delay. Thus I use one while loop (the inner loop) to gather user input.
Also, since I need to get two confirmation (yes or no should be viewed as confirmation), I use another loop (the while(true) loop) to make sure two confirmations are received.
I plan to use the similar code inside the transitionFromAToBOnAny method:
boolean[] confirmed=new boolean[2];
while(true){
for(int i=0; i<2; i++){
String userInput;
while((user=getUserInputFromMicrophone())!=null){
if("Yes".equals(userInput){
confirmed[i]=true;
}else{
confirmed[i]=false;
}
break; //exit loop
}
}
if(confirmed[0]!=null&&confirmed[1]!=null){
break; //exit loop
}
}
fire(MoveToBEvent);
My questions:
1. Should the above code reside in the transitionFromAToBOnAny method or should it reside outside state machine completely?
2. Let us assume that gathering mic input can take 2-5 minutes. The state machine may handle other states like StateC due to some scheduler program, while the getUserInputFromMicrophone() is hanging. After the user input is gathered, I need to fire event inside StateC to activate StateA. When control finally falls in the transitionFromAToBOnAny method, how can I know if the user input is the first one or the second one? Will the state machine remember where the last line of code was executed upon the transition from StateA to StateB given the scheduler program.
Thanks,
Cheng