On Wednesday, April 16, 2014 9:57 AM, Ate Douma <[email protected]> wrote:
Hi Woonsan, > >On 16-04-14 15:49, Woonsan Ko wrote: >> 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] >Actually, since the last milestone SCXMLExecutor no longer is serializable :) >See also https://issues.apache.org/jira/browse/SCXML-197 > >I still need to provide updated documentation for this, but the >SCXMLTestHelper >[2] class has been (and had to be) updated for this changed usage. > >> 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. > >You need to update to the latest milestone 1 or trunk, then you'll see the new >attach/detach instance features ;) Ah, sorry. I haven't updated the code for a while. My comment was based on outdated information then.. Thanks, Woonsan > >> >> 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, "[email protected]" <[email protected]> >> 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: [email protected] >>> For additional commands, e-mail: [email protected] > >>> >>> >>> >>> > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [email protected] >For additional commands, e-mail: [email protected] > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
