Hi,
I want to test the transitFromAnyToBOnToB function in the following code.
I did two things:
1. @Transitions({@Transit(from = "*", to = "B", on = "ToB", callMethod = "transitFromAnyToBOnToB")})
2. builder.transit().fromAny().to("B").on("ToB").callMethod("transitFromAnyToBOnToB");
After I ran the following code, no expected output was shown (actually nothing). But it did show expected result, when I change the first line into:
@Transitions({@Transit(from = "A", to = "B", on = "ToB", callMethod = "transitFromAnyToBOnToB")})
I assume the * should be equivalent to ANYTHING, why it isn't.
Anything wrong with my code?
Thanks!
---------------------------------------------------------------
import org.squirrelframework.foundation.fsm.StateMachineBuilderFactory;import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder;
import org.squirrelframework.foundation.fsm.annotation.ContextInsensitive;
import org.squirrelframework.foundation.fsm.annotation.State;
import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters;
import org.squirrelframework.foundation.fsm.annotation.States;
import org.squirrelframework.foundation.fsm.annotation.Transit;
import org.squirrelframework.foundation.fsm.annotation.Transitions;
import org.squirrelframework.foundation.fsm.impl.AbstractUntypedStateMachine;
public class TestSM {
@Transitions({@Transit(from = "*", to = "B", on = "ToB", callMethod = "transitFromAnyToBOnToB")})
@States({@State(name = "A", exitCallMethod = "leftA"),
@State(name = "B", entryCallMethod = "enterB")})
@StateMachineParameters(stateType = String.class, eventType = String.class, contextType = Integer.class)
@ContextInsensitive
static class UntypedStateMachineBase extends AbstractUntypedStateMachine {
protected StringBuilder logger = new StringBuilder();
protected void leftA(String from, String to, String event) {
logger.append("leftA");
}
protected void exitA(String from, String to, String event) {
logger.append("exitA");
}
protected void enterB(String from, String to, String event) {
logger.append("enterB");
}
protected void transitFromAnyToBOnToB(String from, String to,
String event) {
logger.append("transitFromAnyToBOnToB");
}
public static void main(String[] args) {
UntypedStateMachineBuilder builder = StateMachineBuilderFactory
.create(UntypedStateMachineBase.class);
builder.transit().fromAny().to("B").on("ToB")
.callMethod("transitFromAnyToBOnToB");
UntypedStateMachineBase fsm = builder.newUntypedStateMachine("A");
fsm.start();
fsm.fire("ToB");
System.out.println(fsm.logger);
}
}
}