import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder;
public class DeadLockTest {
private UntypedStateMachine[] getTestingFSMInstances() {
UntypedStateMachineBuilder builder1 = StateMachineBuilderFactory.create(ConcurrentSimpleStateMachine.class);
builder1.transition().from("A").to("B").on("FIRST").perform(
new AnonymousAction<UntypedStateMachine, Object, Object, Object>() {
@Override
public void execute(Object from, Object to, Object event,
Object context, UntypedStateMachine stateMachine) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
UntypedStateMachine fsm2 = (UntypedStateMachine)context;
System.out.println("fsm2 current state: "+fsm2.getCurrentState());
}
});
UntypedStateMachineBuilder builder2 = StateMachineBuilderFactory.create(ConcurrentSimpleStateMachine.class);
builder2.transition().from("C").to("D").on("SECOND").perform(
new AnonymousAction<UntypedStateMachine, Object, Object, Object>() {
@Override
public void execute(Object from, Object to, Object event,
Object context, UntypedStateMachine stateMachine) {
UntypedStateMachine fsm1 = (UntypedStateMachine)context;
System.out.println("fsm1 current state: "+fsm1.getCurrentState());
}
});
final UntypedStateMachine fsm1 = builder1.newStateMachine("A");
fsm1.start();
final UntypedStateMachine fsm2 = builder2.newStateMachine("C");
fsm2.start();
return new UntypedStateMachine[]{fsm1, fsm2};
}