0

I have noticed an issue in using timeouts and redis persistence with statemachinefactory. enter image description here

Above is my uml diagram for the state machine. I have added a stateListener in my code and every time its persisted.

StateMachine stateMachine = factory.getStateMachine();

        stateMachine.addStateListener(new CompositeStateMachineListener<String, String>() {

            @Override
            public void stateContext(StateContext<String, String> arg0) {

                String user = (String) arg0.getExtendedState().getVariables().get("imei");
                if (user == null) {
                    return;
                }

                log.info(arg0.getStage().toString() + "**********" + stateMachine.getState());
                try {
                    redisStateMachinePersister.persist(arg0.getStateMachine(), "testprefixSw:" + user);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }

        });

Note : ExitPointGQ points to a initial state called WAITFORCOMMAND of the parent machine.

Now taking the scenario where I need to wait by giving the signal WAIT, the machine goes back to WaitForGenQueryRes which is right. But by now, the first timer has started and after 60 seconds, the timer fires and exits through the exit point and persists that the state is now at WAITFORCOMMAND whereas it has to be at WaitForGenQueryRes because I looped it.

Please point out my mistake so I could fix this.

  • Maybe there is something I don't understand what that `Wait` state actually do. Does it halt there? Looks like there is anonymous transition from `Wait` to `WaitForGenQueryRes`. Then `after 60000` timer is armed when `WaitForGenQueryRes` is entered and disarmed when `WaitForGenQueryRes` is exited. If there is something in that graph I don't see, I expect that timer to get activated again. – Janne Valkealahti Apr 26 '17 at 08:18
  • There is https://github.com/spring-projects/spring-statemachine/issues/321 fixed in 1.2.3.RELEASED but afaik it should not affect this case. – Janne Valkealahti Apr 26 '17 at 08:21
  • Wait state has an action which I haven't shown here but it just logs that the machine was ordered to wait. The timers are working fine, but the problem is persistence, once the first 60 seconds are over, the state is exited and redis stores that the state now is outside this sub-machine. But I want it to wait for another 60 seconds.. That cannot be achieved as I cannot stop the previous timer – Sachini Wickramaratne Apr 26 '17 at 08:37
  • Hi, when using statemachine factory to create one SM per request, there is a memory problem as something is keeping reference to the SM. It never gets to garbage. Is this the timer? how can I resolve this? – Sachini Wickramaratne May 18 '17 at 05:34
  • You need to show a bit more and some sample code and tests so that I could poke around. – Janne Valkealahti May 18 '17 at 08:27
  • Ok I ill post more of this on a new thread, for the time being, is there a way to limit the number of SM's created by the factory? – Sachini Wickramaratne May 18 '17 at 09:14
  • Not sure I understand a question. You either call factory manually or let pool implementation call it. – Janne Valkealahti May 18 '17 at 13:15
  • https://pastebin.com/N8d7hR8T points to a part of my code. As you can see there I take events from a queue and feed a new state machine from the factory. My problem is, where does the SM go after it's done. There is a huge memory usage when I use the factory, assuming they never get taken by garbage collector. Is there a way to remove the memory reference after its done? – Sachini Wickramaratne May 19 '17 at 05:26
  • http://stackoverflow.com/questions/44065421/spring-statemachine-factory-stays-in-memory please check this out – Sachini Wickramaratne May 19 '17 at 09:52

0 Answers0