commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Woonsan Ko <woon_...@yahoo.com>
Subject Re: SCXML2 Serialization
Date Wed, 16 Apr 2014 13:49:31 GMT
Hi Francis,

I think the best practices are to serialize either o.a.c.s.SCXMLExecutor [1] or o.a.c.s.model.SCXML
instances. Both cases are well-maintained in test code. [2]
In your case, you can probably (de)serialize SCXMLExecutor instance directly to store/load
the execution context.
Also, as far as I can see, SCXMLExecutor doesn't provide #(at|de)tachInstance() methods and
I don't think it would do even later because SCInstance doesn't necessarily have full information
about the current execution context.
So, please (de)serialize the SCXMLExecutor instance instead.

Cheers,

Woonsan

[1] http://commons.apache.org/proper/commons-scxml/faq.html#serializability
[2] http://svn.apache.org/repos/asf/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java



On Wednesday, April 16, 2014 9:07 AM, "tendaf@free.fr" <tendaf@free.fr> wrote:
 
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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message