On Mon, Aug 2, 2010 at 1:40 AM, Prem Chand Majeti <prem.maj...@aricent.com> wrote: > Hi, > > I'm trying to implement simple FSM in java. > > Here is my scxml :- > > <scxml xmlns="http://www.w3.org/2005/07/scxml" > version="1.0" initialstate="first"> > > <state id="first"> > <transition event="event1" target="second" /> > <transition event="event2" target="last" /> > </state> > > <state id="second"> > <transition event="event3" target="last" /> > </state> > > <state id="last" final="true" /> > > </scxml> > > Java Implemetation:- > > public class FsmTest extends AbstractStateMachine { > > public FsmTest(URL scxmlDocument) { > super(scxmlDocument); > } > > public void first() { > //Some process... > if(..) > fireEvent("event1"); > else > fireEvent("event2"); > } > <snip/>
The above is a bit of an anti-pattern for the simple AbstractStateMachine class. The mapped methods (such as "first" above) are executed synchronously as part of the onentry processing for the corresponding states. Firing a new event synchronously while still processing a previous one isn't recommended. Many possible solutions. To name a few: * Override the fireEvent() method to be asynchronous (in a new thread, perhaps with some wait time) * Add a first-class event queue to an AbstractStateMachine subclass and add events to the queue from where they get processed in sequence * Use one of the more sophisticated patterns (see [1]) than the simple AbstractStateMachine class -Rahul [1] http://commons.apache.org/scxml/guide/using-commons-scxml.html > public void second() { > // Some Process.... > fireEvent("event3"); > } > > public void last() { > } > > } > > When I try to run this, it was entering into the state "first". But from > there no event was fired and it was not moving to other states. > Please let me know if I was doing something wrong. > > Thanks & Regards > Prem > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org