Giter Site home page Giter Site logo

Comments (5)

claudio-rosati avatar claudio-rosati commented on May 16, 2024

The listeners I've added are the following:

public void attachListenersToFSM () {
  fsm.addStartListener(startListener);
  fsm.addStateMachineExceptionListener(stateMachineExceptionListener);
  fsm.addStateMachineListener(stateMachineListener);
  fsm.addTransitionBeginListener(transitionBeginListener);
  fsm.addTransitionCompleteListener(transitionCompleteListener);
  fsm.addTransitionDeclinedListener(transitionDeclinedListener);
  fsm.addTransitionEndListener(transitionEndListener);
  fsm.addTransitionExceptionListener(transitionExceptionListener);
}

removed in the following order:

public void detachListenersToFSM () {
  fsm.removeTransitionExceptionListener(transitionExceptionListener);
  fsm.removeTransitionEndListener(transitionEndListener); // <== Exception thrown
  fsm.removeTransitionDecleindListener(transitionDeclinedListener);
  fsm.removeTransitionCompleteListener(transitionCompleteListener);
  fsm.removeTransitionBeginListener(transitionBeginListener);
  fsm.removeStateMachineListener(stateMachineListener);
  fsm.removeStateMachineExceptionListener(stateMachineExceptionListener);
  fsm.removeStartListener(startListener);
}

from squirrel.

hekailiang avatar hekailiang commented on May 16, 2024

It would be helpful if you can provide a runnable test case to reproduce the issue.

from squirrel.

claudio-rosati avatar claudio-rosati commented on May 16, 2024

Here a test case: it's a mixture of my code and your example... but it works throwing the exception.
Java 8 is required for the lambda expressions.

import org.squirrelframework.foundation.fsm.StateMachine;
import org.squirrelframework.foundation.fsm.StateMachineBuilderFactory;
import org.squirrelframework.foundation.fsm.UntypedStateMachine;
import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder;
import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters;
import org.squirrelframework.foundation.fsm.impl.AbstractUntypedStateMachine;


public class QuickStartSample {

    private static final StateMachine.StartListener startListener = e -> started(e);
    private static final StateMachine.StateMachineExceptionListener stateMachineExceptionListener = e -> stateMachineException(e);
    private static final StateMachine.StateMachineListener stateMachineListener = e -> stateMachineEvent(e);
    private static final StateMachine.TransitionBeginListener transitionBeginListener = e -> transitionBegin(e);
    private static final StateMachine.TransitionCompleteListener transitionCompleteListener = e -> transitionComplete(e);
    private static final StateMachine.TransitionDeclinedListener transitionDeclinedListener = e -> transitionDeclined(e);
    private static final StateMachine.TransitionEndListener transitionEndListener = e -> transitionEnd(e);
    private static final StateMachine.TransitionExceptionListener transitionExceptionListener = e -> transitionException(e);

    public static void main ( String[] args ) {

        UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(StateMachineSample.class);

        builder.externalTransition().from("A").to("B").on(FSMEvent.ToB).callMethod("fromAToB");
        builder.onEntry("B").callMethod("ontoB");

        UntypedStateMachine fsm = builder.newStateMachine("A");

        attachListenersToFSM(fsm);
        fsm.fire(FSMEvent.ToB, 10);
        detachListenersFromFSM(fsm);

        System.out.println("Current state is " + fsm.getCurrentState());

    }

    public static void attachListenersToFSM ( UntypedStateMachine fsm ) {
        fsm.addStartListener(startListener);
        fsm.addStateMachineExceptionListener(stateMachineExceptionListener);
        fsm.addStateMachineListener(stateMachineListener);
        fsm.addTransitionBeginListener(transitionBeginListener);
        fsm.addTransitionCompleteListener(transitionCompleteListener);
        fsm.addTransitionDeclinedListener(transitionDeclinedListener);
        fsm.addTransitionEndListener(transitionEndListener);
        fsm.addTransitionExceptionListener(transitionExceptionListener);
    }

    public static void detachListenersFromFSM ( UntypedStateMachine fsm ) {
        fsm.removeTransitionExceptionListener(transitionExceptionListener);
        fsm.removeTransitionEndListener(transitionEndListener);
        fsm.removeTransitionDecleindListener(transitionDeclinedListener);
        fsm.removeTransitionCompleteListener(transitionCompleteListener);
        fsm.removeTransitionBeginListener(transitionBeginListener);
        fsm.removeStateMachineListener(stateMachineListener);
        fsm.removeStateMachineExceptionListener(stateMachineExceptionListener);
        fsm.removeStartListener(startListener);
    }

    private static void started ( StateMachine.StartEvent e) {
    }

    private static void stateMachineEvent ( StateMachine.StateMachineEvent e) {
    }

    private static void stateMachineException ( StateMachine.StateMachineExceptionEvent e) {
    }

    private static void transitionBegin ( StateMachine.TransitionBeginEvent e) {
    }

    private static void transitionComplete ( StateMachine.TransitionCompleteEvent e) {
    }

    private static void transitionDeclined ( StateMachine.TransitionDeclinedEvent e) {
    }


    private static void transitionEnd (StateMachine.TransitionEndEvent e) {
    }

    private static void transitionException (StateMachine.TransitionExceptionEvent e) {
    }

    @StateMachineParameters( stateType = String.class, eventType = FSMEvent.class, contextType = Integer.class )
    static class StateMachineSample extends AbstractUntypedStateMachine {

        protected void fromAToB ( String from, String to, FSMEvent event, Integer context ) {
            System.out.println("Transition from '" + from + "' to '" + to + "' on event '" + event + "' with context '" + context + "'.");
        }

        protected void ontoB ( String from, String to, FSMEvent event, Integer context ) {
            System.out.println("Entry State \'" + to + "\'.");
        }

    }

    enum FSMEvent {

        ToA, ToB, ToC, ToD

    }

}

from squirrel.

hekailiang avatar hekailiang commented on May 16, 2024

I just fixed the issue. Please try latest snapshot version.

from squirrel.

claudio-rosati avatar claudio-rosati commented on May 16, 2024

I've tested the latest snapshot and it is working correctly.
Thank you.

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.