commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ten...@free.fr
Subject SCXML2 Serialization
Date Wed, 16 Apr 2014 13:07:04 GMT
Hi all,

I would like to know the best practice to serialize/deserialize SCXML fsm.

I do this during the creation of the SCXML executor, scInstace is the serialized context:

            List<CustomAction> customActions = new ArrayList<CustomAction>();
            CustomAction ca =
                    new CustomAction("http://my.custom-actions.domain/CUSTOM1",
                            "hello", Hello.class);
            customActions.add(ca);

            JexlEvaluator evaluator = new JexlEvaluator();

            try {
                scxml = SCXMLReader.read(StopWatch.class.getClassLoader().

            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }


            executor = null;
            try {
                executor = new SCXMLExecutor(evaluator, null, new SimpleErrorReporter());

                if (scInstance != null) {
                    // serialized context use it
                    executor.attachInstance(scInstance);
                    executor.registerInvokerClass("x-test", DummyInvoker.class);
                    executor.setStateMachine(scxml);
                    executor.go();
                    setInitialState(executor, "paused");
                } else {
                    // new context
                    Context rootContext = new JexlContext();
                    rootContext.set("var1", "value1");
                    executor.registerInvokerClass("x-test", DummyInvoker.class);
                    executor.setStateMachine(scxml);
                    executor.setRootContext(rootContext);
                    executor.go();
                }

            } catch (ModelException me) {
                // Executor initialization failed, because the
                // state machine specified has inconsistencies
                me.printStackTrace();
            }

I serialize executor.detachInstance(). It's seem to work, but is it the right way to restart
a SCXML 'session' ?

Thanks
Francis.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message