Giter Club home page Giter Club logo

Comments (16)

himanshuvirmani avatar himanshuvirmani commented on August 18, 2024 3

I am also getting the same error. Was this issue resolved/identified?

UPDATE: It is forcing me to keep inner state machine class to be static to make it work.

from squirrel.

winder avatar winder commented on August 18, 2024 2

You get this same error if your StateMachine machine object constructor has an argument and you don't specify the argument type in StateMachineBuilderFactory.create or don't provide the argument in newStateMachine.

from squirrel.

hekailiang avatar hekailiang commented on August 18, 2024

which sample does not work?

from squirrel.

conanzxn avatar conanzxn commented on August 18, 2024

Please find the code below.

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 StandaloneStateMachineTest {
     // 1. Define State Machine Event
    enum FSMEvent {
        ToA, ToB, ToC, ToD
    }

    // 2. Define State Machine Class
    @StateMachineParameters(stateType=String.class, eventType=FSMEvent.class, contextType=Integer.class)
    static class StateMachineSample extends AbstractUntypedStateMachine {

        StateMachineSample() {

        }

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

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

    public static void main(String[] args) {
        // 3. Build State Transitions
        UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(StateMachineSample.class);
        builder.externalTransition().from("A").to("B").on(FSMEvent.ToB).callMethod("fromAToB");
        builder.onEntry("B").callMethod("ontoB");

        // 4. Use State Machine
        UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.fire(FSMEvent.ToB, 10);

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

from squirrel.

hekailiang avatar hekailiang commented on August 18, 2024

I do not have any problem to run your sample code. Everything works fine. And I cannot see why this simple code breaks. Any error stack information?

from squirrel.

conanzxn avatar conanzxn commented on August 18, 2024

I got the exception below when I run this.

Exception in thread "main" org.squirrelframework.foundation.exception.SquirrelRuntimeException: 00010007 : couldn't construct new 'null' with args [fromAToB, org.squirrelframework.foundation.fsm.impl.ExecutionContext@305f849].

from squirrel.

conanzxn avatar conanzxn commented on August 18, 2024
org.squirrelframework.foundation.exception.SquirrelRuntimeException: 00010007 : couldn't construct new 'null' with args [fromAToB, org.squirrelframework.foundation.fsm.impl.ExecutionContext@19fe59c2].
    at org.squirrelframework.foundation.util.ReflectUtils.newInstance(ReflectUtils.java:255)
    at org.squirrelframework.foundation.util.ReflectUtils.newInstance(ReflectUtils.java:228)
    at org.squirrelframework.foundation.component.SquirrelProvider.newInstance(SquirrelProvider.java:57)
    at org.squirrelframework.foundation.component.SquirrelProvider.newInstance(SquirrelProvider.java:38)
    at org.squirrelframework.foundation.fsm.impl.FSM.newMethodCallActionProxy(FSM.java:103)
    at org.squirrelframework.foundation.fsm.impl.TransitionBuilderImpl.callMethod(TransitionBuilderImpl.java:54)

from squirrel.

hekailiang avatar hekailiang commented on August 18, 2024

Since the issue cannot be produced and no other user report this problem. I will close this issue for now. If more information can be provided and can prove this is a bug, please reopen the issue.

from squirrel.

LouisPennachio avatar LouisPennachio commented on August 18, 2024

I am having the exact same issue, please check this for more details: https://stackoverflow.com/questions/47674628/how-to-create-a-typed-fsm-using-squirrel-fsm-framework

from squirrel.

hekailiang avatar hekailiang commented on August 18, 2024
package org.squirrelframework.foundation.issues;

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.annotation.Transit;
import org.squirrelframework.foundation.fsm.annotation.Transitions;
import org.squirrelframework.foundation.fsm.impl.AbstractUntypedStateMachine;

public class IssueSample {
    enum TestEvent {
        toA, toB, toC, toD
    }

    @Transitions({
            @Transit(from="A", to="B", on="toB", callMethod="fromAToB"),
            @Transit(from="B", to="C", on="toC"),
            @Transit(from="C", to="D", on="toD")
    })

    @StateMachineParameters(stateType=String.class, eventType=TestEvent.class, contextType=Integer.class)
    static class UntypedStateMachineSample extends AbstractUntypedStateMachine {
        // No need to specify constructor anymore since 0.2.9
        // protected UntypedStateMachineSample(ImmutableUntypedState initialState,
        //  Map<Object, ImmutableUntypedState> states) {
        //    super(initialState, states);
        // }

        protected void fromAToB(String from, String to, TestEvent event, Integer context) {
            System.out.println("fromAToB");
        }

        protected void transitFromDToAOntoA(String from, String to, TestEvent event, Integer context) {
            // transition action still type safe ...
            System.out.println("transitFromDToAOntoA");
        }
    }

    public static void main(String[] args) {
        UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(
                UntypedStateMachineSample.class);
        // state machine builder not type safe anymore
        builder.externalTransition().from("D").to("A").on(TestEvent.toA);
        UntypedStateMachine fsm = builder.newStateMachine("A");
        fsm.fire(TestEvent.toB);
    }
}```  

the sample code works as expected

from squirrel.

LouisPennachio avatar LouisPennachio commented on August 18, 2024

yes, but I am refering to the example in the "Untyped state machine" section, which is not working for me.

Here it is :

enum TestEvent {
     toA, toB, toC, toD
}

@Transitions({
    @Transit(from="A", to="B", on="toB", callMethod="fromAToB"),
    @Transit(from="B", to="C", on="toC"),
    @Transit(from="C", to="D", on="toD")
})

@StateMachineParameters(stateType=String.class, eventType=TestEvent.class, contextType=Integer.class)
class UntypedStateMachineSample extends AbstractUntypedStateMachine {
    // No need to specify constructor anymore since 0.2.9
    // protected UntypedStateMachineSample(ImmutableUntypedState initialState,
    //  Map<Object, ImmutableUntypedState> states) {
    //    super(initialState, states);
    // }

    protected void fromAToB(String from, String to, TestEvent event, Integer context) {
        // transition action still type safe ...
    }

    protected void transitFromDToAOntoA(String from, String to, TestEvent event, Integer context) {
        // transition action still type safe ...
    }
}

UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(
UntypedStateMachineSample.class);
// state machine builder not type safe anymore
builder.externalTransition().from("D").to("A").on(TestEvent.toA);
UntypedStateMachine fsm = builder.newStateMachine("A");

from squirrel.

18910949204 avatar 18910949204 commented on August 18, 2024

yes, but I am refering to the example in the "Untyped state machine" section, which is not working for me.

Here it is :

enum TestEvent {
     toA, toB, toC, toD
}

@Transitions({
    @Transit(from="A", to="B", on="toB", callMethod="fromAToB"),
    @Transit(from="B", to="C", on="toC"),
    @Transit(from="C", to="D", on="toD")
})

@StateMachineParameters(stateType=String.class, eventType=TestEvent.class, contextType=Integer.class)
class UntypedStateMachineSample extends AbstractUntypedStateMachine {
    // No need to specify constructor anymore since 0.2.9
    // protected UntypedStateMachineSample(ImmutableUntypedState initialState,
    //  Map<Object, ImmutableUntypedState> states) {
    //    super(initialState, states);
    // }

    protected void fromAToB(String from, String to, TestEvent event, Integer context) {
        // transition action still type safe ...
    }

    protected void transitFromDToAOntoA(String from, String to, TestEvent event, Integer context) {
        // transition action still type safe ...
    }
}

UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(
UntypedStateMachineSample.class);
// state machine builder not type safe anymore
builder.externalTransition().from("D").to("A").on(TestEvent.toA);
UntypedStateMachine fsm = builder.newStateMachine("A");

notice that your Class UntypedStateMachineSample should be static

from squirrel.

yqsas avatar yqsas commented on August 18, 2024

I am also getting the same error.
Because I added a constructor with arguments in my custome StateMachine,and when create it without the arguments

from squirrel.

cnmuc avatar cnmuc commented on August 18, 2024

Same error here. Tried all versions 0.2.7 -> 0.3.8. Tried sample code, also tried the code from the comments here.

from squirrel.

cnmuc avatar cnmuc commented on August 18, 2024

The problem can be reproduced by adding to pom,xml

<dependency>
    <groupId>com.google.collections</groupId>
    <artifactId>google-collections</artifactId>
    <version>1.0</version>
</dependency>

from squirrel.

cnmuc avatar cnmuc commented on August 18, 2024

Opened a new issue #102

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.