简体   繁体   中英

how to call Invoker again on same state in apache commons SCXML

I have used Apache commons SCXML for maintaining state machine in my project. We have used the Invoker to perform some activities as soon as the transition to the state,for which invoker is defined, is performed.

Issue is coming when invoker is called twice from same state. For example, from State "A" event "TEMP" is fired, then it moves to state "B". And as soon as it enters the state "B" invoker is called and callback method invoke() of Invoker class is being called.

<state id="A">
    <transition event="TEMP" target="B"></transition>
</state>

<state id="B">
    <invoke src="INVOKER" targettype="invoker-req">
        <transition event="FAIL" target="A"></transition>
        <transition event="SUCC" target="C"></transition>
    </invoke>
</state>

Problem is coming when event "TEMP" is fired again from State A and then Invoker is not getting called. invoke() method is never called again. Can the invoker be called only once?

Please let me know how can I call the invoker/invoke() again. I am not getting much help on internet.

Thanks in advance.

I am not sure about the details of the apache-commons implementation, but the SCXML specification mandates that invokers are called when their containing state is in the active configuration at the end of a macrostep and uninvoked when this state is no longer in the active configuration at the end of a macrostep. As such, there can only ever be a single instance of an invoker running, regardless from which state you came.

What you can do, however, is to start the invoker in a parent state and send events with its id as the #_target in an onentry block. You can send as many events as you like and move your application code from the invokers instantiation to the reception of an event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM