transitFromAnyToBOnToB doesn't work!

37 views
Skip to first unread message

Cheng

unread,
Feb 12, 2015, 6:30:42 AM2/12/15
to squirrel-st...@googlegroups.com
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!

---------------------------------------------------------------
package com.test.org

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);
}
}

}

vishal gaurav

unread,
Feb 12, 2015, 7:33:44 AM2/12/15
to squirrel-st...@googlegroups.com
I think fromAny attach a transition to already existing transition but doesn't create a new transition. See the user guide ,

Note: These action methods will be attached to matched and already existed transitions but not to create any new transitions.

He Henry

unread,
Feb 12, 2015, 10:58:05 PM2/12/15
to squirrel-st...@googlegroups.com
This is the point. :)

在 2015年2月12日星期四 UTC+8下午8:33:44,vishal gaurav写道:
Reply all
Reply to author
Forward
0 new messages