Giter Site home page Giter Site logo

Comments (3)

hekailiang avatar hekailiang commented on May 16, 2024

Thanks for reporting this issue. Normally transition should only be triggered once when single event fired. I don't know what is the problem now. It would be helpful if you could provide complete runnable test case to reproduce the issue.

from squirrel.

dsGCloud avatar dsGCloud commented on May 16, 2024

It's weird because I'm just checking the FSM with keyboard events.

public class OrangutanWriter {

private static OrangutanWriterFSM StateMachine;

public static void setup() {
    StateMachineBuilder<OrangutanWriterFSM, FSMState, FSMEvent, Void> builder = StateMachineBuilderFactory
            .create(OrangutanWriterFSM.class, FSMState.class,
                    FSMEvent.class, Void.class);

    builder.onExit(FSMState.StandBy).callMethod("exitStandBy");

    builder.externalTransition().from(FSMState.StandBy).to(FSMState.Stream)
            .on(FSMEvent.Connected).callMethod("entryStream");

    builder.onExit(FSMState.Stream).callMethod("exitStream");

    builder.externalTransition().from(FSMState.Stream).to(FSMState.Encode)
            .on(FSMEvent.EncodeList).callMethod("Encode");

    // 4. Use State Machine
    StateMachine = builder.newStateMachine(FSMState.StandBy);

}

public static void main(String[] args) {
    setup();
    StateMachine.start();

    while (true) {
        int myint = 0;
        Scanner keyboard = new Scanner(System.in);
        System.out.println("You are at: " + StateMachine.getCurrentState()
                + "\nEnter an integer:");
        myint = keyboard.nextInt();
        switch (myint) {
        case 1:
            System.out.println("My Int = " + myint);
            StateMachine.fire(FSMEvent.Connected);
            myint = 0;
            break;

        case 4:
            StateMachine.fire(FSMEvent.EncodeList);
            break;

        case 5:
            StateMachine.fire(FSMEvent.StopEncode);
            break;
        default:
            break;
        }
    }

}

}

from squirrel.

rookie0peng avatar rookie0peng commented on May 16, 2024

FSM will call method "exitStandBy" when you initial FSM.
like this.
StateMachine = builder.newStateMachine(FSMState.StandBy);
Because of this code.
builder.onExit(FSMState.StandBy).callMethod("exitStandBy");
You can avoid initial call by check FSMEvent is not null.
protected void exitStandBy(FSMState from, FSMState to, FSMEvent event, Void context) { if (event != null) { //your code } }

from squirrel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.