[scxml] Setting state through history element or other means
Hello, Is there a way to programatically change history state of a workflow? Our idea is to be able to set freely the next state to be executed. If we set the state like this: Set states = executor.getCurrentStatus().getStates(); TransitionTarget tt = (TransitionTarget) executor.getStateMachine().getTargets().get(stateId); states.clear(); states.add(tt); This will set current state, but onentry will not be executed, only onexit on transition. Perhaps if we could somehow programatically change current status of the executor, so that when we trigger an event that has target=historyElement, the state machine will transition to the wanted state. Is this possible?
Re: [scxml] Handling condition errors in transitions
2011/9/13 Rahul Akolkar rahul.akol...@gmail.com When the state machine is in state2, there are three candidate transitions that match event action.next -- two with guards in state2 and one unguarded or condition-less in state _processing. The two in state2 are not followed, but subsequently the unguarded one is selected and followed which leads to state _end. Given state _end is a final state, no further events triggered on the state machine will have any effect. -Rahul Thank you Rahul. There is no way to catch the parsing error if it happens in such conditions, and consequently trigger an error event?
[scxml] Handling condition errors in transitions
Hello, I have an SCXML workflow as given below. The conditions in the transitions of state2 are invalid because they have an invalid variable name trans-0. The application was made in the way that on each step forward, it triggers an action.next event, followed by any external events inserted by a custom ErrorReporter. This way, the workflow would move to the _error state on every error. The problem is that on parsing of state2 transition conditions, it did not move to _error state. The following sequence ocurred: 1) Workflow follows to state2 2) Current state is state2, application triggers an action.next event 3) ErrorReported inserted two action.error events in the queue 4) However, the workflow is already in _end state (why?) 5) Application reads the external events queue, triggers two action.error events, but nothing happens because workflow is in _end state Why workflow ends up in _end state after parsing error? *scxml xmlns=**http://www.w3.org/2005/07/scxml*http://www.w3.org/2005/07/scxml * version=1.0 initialstate=_start* *state id=_start transition target=_processing / /state* *state id=_processing* *initial transition target=_actions/ /initial* *history id=_history type=deep* */history state id=_actions initial=state1 state id=state1 transition event=action.next target=state2 / /state* *state id=state2 transition event=action.next cond=trans-0.parameter.P_InitialBalance == 7 target=state3 / transition event=action.next cond=trans-0.parameter.P_InitialBalance == 0 target=state4 / /state* *state id=state3 transition event=action.next target=state5 / /state* *state id=state4 transition event=action.next target=state5 / /state* *state id=state5 /state /state* *transition event=action.next target=_end /* *transition event=action.end target=_end/* *transition event=error.* target=_error /* */state* *state id=_error* *onentry log expr='In error'/ /onentry* *transition event=action.next target=_history/* *transition event=action.end target=_end/* */state* *state id=_end final=true* */state* */scxml*
[scxml] SCXML model thread-safe?
Is the SCXML model thread-safe? We're considering to parse the SCXML files on application startup and then store the resulting SCXML models in a cache where multiple threads will access them. Should we expect any inconsistencies? Note that executors will not be cached, and a new executor will be created per request. Thank you!
Re: [scxml] SCXML model thread-safe?
Thank you Rahul. In regards to custom actions in such usage case, from what we've seen, a new instance of the custom action class is created on each execution of the action. This makes it impossible for two threads to access the same custom action object simultaneously. Am I correct? 2011/7/5 Rahul Akolkar rahul.akol...@gmail.com On Tue, Jul 5, 2011 at 3:37 AM, Dario D darac1...@gmail.com wrote: Is the SCXML model thread-safe? We're considering to parse the SCXML files on application startup and then store the resulting SCXML models in a cache where multiple threads will access them. Should we expect any inconsistencies? Note that executors will not be cached, and a new executor will be created per request. snip/ The above usage pattern is fine. We have a test or two running in the nightlies that does the above (one model, many executors). Ofcourse, I'd recommend authoring tests that closely match your scenario as well. -Rahul Thank you! - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[scxml] src element as a pointer to memory content
Hello, Would it be possible to have a PathResolver implementation which treats the src element as a pointer to a database entry where content is stored, or an in-memory object? Of course, I could make a PathResolver implementation which will parse the value of src make a query to the database, download the content to a file, and then return file path as the result of the resolvePath() method. However, I would like to skip the step of making a file on the disk just for the purpose of loading the src content. Ideally, this PathResolver implementation would be able to read content directly from a memory object (perhaps a cache of some sort), without the need of creating a file. I'm planning to use SCXML in a high-throughtput environment and I feel that writing files on the disk and then reading them back will slow the process down a bit. One of the requirements for the application is to be able to split SCXML files into many reusable modules, thus the need to use the src element. Any thoughts?
Re: [scxml] src element as a pointer to memory content
Thank you Rahul. In fact we were investigating the possibility of having our own protocol handlers, but we noticed that the resolve() method of PathResolver returned a string, not an URL. What did you have in mind? 2011/6/7 Rahul Akolkar rahul.akol...@gmail.com On Mon, Jun 6, 2011 at 5:35 PM, Dario D darac1...@gmail.com wrote: Hello, Would it be possible to have a PathResolver implementation which treats the src element as a pointer to a database entry where content is stored, or an in-memory object? Of course, I could make a PathResolver implementation which will parse the value of src make a query to the database, download the content to a file, and then return file path as the result of the resolvePath() method. However, I would like to skip the step of making a file on the disk just for the purpose of loading the src content. Ideally, this PathResolver implementation would be able to read content directly from a memory object (perhaps a cache of some sort), without the need of creating a file. I'm planning to use SCXML in a high-throughtput environment and I feel that writing files on the disk and then reading them back will slow the process down a bit. One of the requirements for the application is to be able to split SCXML files into many reusable modules, thus the need to use the src element. Any thoughts? snip/ Requirement is reasonable, my suggestion would be to investigate using your own scheme for the resolved URLs and providing a custom stream protocol handler that reads from memory or cache as desired. For more on how to do this, see the java.net.URL class docs, in particular, the portion here: http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html#URL(java.lang.String,%20java.lang.String,%20int,%20java.lang.String) Separately, you should be aware that the src attribute has been removed from the SCXML spec in favor of standard techniques like XInclude, though Commons SCXML will continue to support it till the next major release. -Rahul - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [scxml] Questions about error events and setting workflow state
2011/5/12 Rahul Akolkar rahul.akol...@gmail.com On Thu, May 12, 2011 at 6:56 AM, Dario D darac1...@gmail.com wrote: 2) One requirement for the application is to allow setting an arbitrary state in a workflow. For example, if we have the following workflow: A-B-C-D-E and the workflow is currently in state D, a user should be able to move the workflow back to state B (or any other state). We were considering to use the following way (from the mailing list archives): public void setState(String state) { Set states = getCurrentStatus().getStates(); TransitionTarget tt = getStateMachine().getTargets().get(state); states.clear(); states.add(tt); } Would you recommend doing it this way and how would this affect on any context which was previously set? snap/ It'd likely be OK with the drawback that it hides these transitions from the SCXML document (so anyone staring at the document doesn't see the whole picture). The above doesn't have any effect on the set context(s). Thank you for your feedback, as always. In regards to the question and the workflow example, let's suppose that a user has set the current state to B after being in state D. Any local context which may have been created in states C and D will remain associated to those states, until it gets overwritten when the workflow transitions again to C and D, am I right? To continue on the same workflow example, let's supposed that the worklow is in state B. A bug in the workflow has been found at some later stage (states C, D, E) and the user would like to correct this bug before continuing execution of the workflow. Restarting the workflow is not a good idea because actions executed in states A and B are too expensive to be repeated. He corrects this bug and creates a new version of the worfklow model. The application will then call the following method on the existing executor: exec.setStateMachine(newWorkflowModel); This effectively means that the above method would would've been called twice on the executor (when the executor was first created before exec.go(), and after the workflow has been corrected). Is this the right thing to do and again, how would it affect the context which was made during initialization of the worklow and in states A and B? If this is not a good idea, can you suggest any alternatives?
[scxml] Questions about error events and setting workflow state
We're developing an application which will use SCXML for its workflow and I would ask you for advice on a couple of topics: 1) All workflows will have a single state which is called error. Whenever a custom action catches an error, it will fire a derived event and this will cause the workflow go to the error state. Is it possible to expand this functionality to other execution errors? For example when an assignment is made to an undefined variable, or when an expression error happens, to fire an error event. I've tried making transitions that listen to error.* ( http://www.w3.org/TR/scxml/#ErrorEvents) but they are not being used. I was also hoping to raise this event from ErrorReporter but we don't have a mechanism to raise events from there. 2) One requirement for the application is to allow setting an arbitrary state in a workflow. For example, if we have the following workflow: A-B-C-D-E and the workflow is currently in state D, a user should be able to move the workflow back to state B (or any other state). We were considering to use the following way (from the mailing list archives): public void setState(String state) { Set states = getCurrentStatus().getStates(); TransitionTarget tt = getStateMachine().getTargets().get(state); states.clear(); states.add(tt); } Would you recommend doing it this way and how would this affect on any context which was previously set?
Re: [scxml] Calling go() twice
Rahul, in regards to triggering events, I am trying to trigger them from within the workflow like this: datamodel data name=testEvent expr='some test event'/ /datamodel state id=action1 onentry log expr='entering action1'/ send event=testEvent/ /onentry transition event=testEvent target=action2/ onexit log expr='exiting action1'/ /onexit /state state id=action2 onentry log expr='action2'/ /onentry /state As you can see, I am trying to trigger an event from within action1 state and then move to action2. However, this does not happen and the log output shows only entering action1. If the event is being triggered, why the transition does not take place? Thank you. 2011/5/3 Rahul Akolkar rahul.akol...@gmail.com On Tue, May 3, 2011 at 10:13 AM, Dario D darac1...@gmail.com wrote: Thanks Jocke. How would you suggest to resume the the last state before the condition was not met? Let's say that the condition was made valid somehow. How to resume from the last state? To continue the previous example: try { exec.go(); // Execution stops at state2, condition is not met // Condition is made valid through some means // How to resume? } catch (ModelException e) { e.printStackTrace(); } snip/ Triggering events is here: http://commons.apache.org/scxml/guide/core-events.html The main page for the user guide, which has more, is here: http://commons.apache.org/scxml/guide.html If you're using EL, you've have to use the EL syntax for expressions, so rather than the following from your example ... transition target=state3 cond=1 = 2 / ... the syntax will be like below: transition target=state3 cond=${1 eq 2} / -Rahul 2011/5/3 jocke eriksson joakim.eriks...@albatross.com exec.go(); should only be called once. It will start the state machine and it will go through all steps that meets the criteria (event cond). Regards Jocke. 2011/5/3 Dario D darac1...@gmail.com: Hello all, I've just started using SCXML and it's great. However, I've hit a brick wall and I can't seem to figure out something. I have the following XML file: scxml xmlns=http://www.w3.org/2005/07/scxml; version=1.0 initialstate=state1 state id=state1 onentry log expr=State 1/ /onentry transition target=state2 / /state state id=state2 onentry log expr=State 2/ /onentry transition target=state3 cond=1 = 2 / /state state id=state3 final=true onentry log expr=State 3/ /onentry /state /scxml Now, I execute the state machine like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new ELEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new ELContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); // Start execution try { exec.go(); exec.go(); } catch (ModelException e) { e.printStackTrace(); } As you can see I call exec.go() two times. I would expect that in the first time, the state machine will stop in the state2 state and remain there, because condition is not satisfied for going into state3. However, when exec.go() is called the second time, it goes from the start. Effectively, it acts as exec.reset()? Following output is provided: 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 Could you explain this behavior? - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [scxml] Calling go() twice
Thank you Rahul for your fast response. So, the syntax is: state id=action1 onentry log expr='entering action1'/ send event='testEvent'/ /onentry transition event=testEvent target=action2/ onexit log expr='exiting action1'/ /onexit /state and this works. 2011/5/10 Rahul Akolkar rahul.akol...@gmail.com On Tue, May 10, 2011 at 8:51 AM, Dario D darac1...@gmail.com wrote: Rahul, in regards to triggering events, I am trying to trigger them from within the workflow like this: datamodel data name=testEvent expr='some test event'/ /datamodel state id=action1 onentry log expr='entering action1'/ send event=testEvent/ /onentry transition event=testEvent target=action2/ onexit log expr='exiting action1'/ /onexit /state state id=action2 onentry log expr='action2'/ /onentry /state As you can see, I am trying to trigger an event from within action1 state and then move to action2. However, this does not happen and the log output shows only entering action1. If the event is being triggered, why the transition does not take place? snip/ I'll assume you're using JEXL given your previous post. If so, you'll need single quotes around the event name like so (its treated as an expression - spaces added below for readability): event= 'testEvent' If you pass in an application log, you'll see a warn level message to the effect of expression not resolving to a (non-empty) event name string. -Rahul Thank you. 2011/5/3 Rahul Akolkar rahul.akol...@gmail.com On Tue, May 3, 2011 at 10:13 AM, Dario D darac1...@gmail.com wrote: Thanks Jocke. How would you suggest to resume the the last state before the condition was not met? Let's say that the condition was made valid somehow. How to resume from the last state? To continue the previous example: try { exec.go(); // Execution stops at state2, condition is not met // Condition is made valid through some means // How to resume? } catch (ModelException e) { e.printStackTrace(); } snip/ Triggering events is here: http://commons.apache.org/scxml/guide/core-events.html The main page for the user guide, which has more, is here: http://commons.apache.org/scxml/guide.html If you're using EL, you've have to use the EL syntax for expressions, so rather than the following from your example ... transition target=state3 cond=1 = 2 / ... the syntax will be like below: transition target=state3 cond=${1 eq 2} / -Rahul 2011/5/3 jocke eriksson joakim.eriks...@albatross.com exec.go(); should only be called once. It will start the state machine and it will go through all steps that meets the criteria (event cond). Regards Jocke. 2011/5/3 Dario D darac1...@gmail.com: Hello all, I've just started using SCXML and it's great. However, I've hit a brick wall and I can't seem to figure out something. I have the following XML file: scxml xmlns=http://www.w3.org/2005/07/scxml; version=1.0 initialstate=state1 state id=state1 onentry log expr=State 1/ /onentry transition target=state2 / /state state id=state2 onentry log expr=State 2/ /onentry transition target=state3 cond=1 = 2 / /state state id=state3 final=true onentry log expr=State 3/ /onentry /state /scxml Now, I execute the state machine like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new ELEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new ELContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); // Start execution try { exec.go(); exec.go(); } catch (ModelException e) { e.printStackTrace(); } As you can see I call exec.go() two times. I would expect that in the first time, the state machine will stop in the state2 state and remain there, because condition is not satisfied for going into state3. However, when exec.go() is called the second time, it goes from the start. Effectively, it acts as exec.reset()? Following output is provided: 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null
[scxml] Creating ad-hoc arrays in JEXL expressions
Hello, I am trying to create an ad-hoc array in my workflow and provide it to a custom action: state id=fetchCustomerData onentry log expr='Customer - Fetching data'/ al:fetchTableData select=['col1', 'col2'] / /onentry /state In the custom action, I am evaluating this string through JEXL Evaluator: public void execute(EventDispatcher eventDispatcher, ErrorReporter errorReporter, SCInstance scInstance, Log log, Collection collection) throws ModelException, SCXMLExpressionException { log.info(scInstance.getEvaluator().eval(scInstance.getRootContext(), this.getSelect())); } This throws an error: WARNING: EXPRESSION_ERROR (eval('['col1', 'col2']'):Encountered [ at line 1, column 1. Was expecting one of: EOF INTEGER_LITERAL ... FLOAT_LITERAL ... { ... empty ... ( ... size ... - ... ~ ... ! ... not ... null ... true ... false ... ; ... if ... while ... foreach ... IDENTIFIER ... STRING_LITERAL ... ): Is creating arrays (or HashMaps, for that matter) even possible like this in SCXML? I was following the guide at: http://commons.apache.org/jexl/reference/syntax.html The executor was created like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new JexlContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); Thank you!
Re: [scxml] Creating ad-hoc arrays in JEXL expressions
Thanks a lot Rahul. 2011/5/10 Rahul Akolkar rahul.akol...@gmail.com On Mon, May 9, 2011 at 4:19 PM, Dario D darac1...@gmail.com wrote: Hello, I am trying to create an ad-hoc array in my workflow and provide it to a custom action: state id=fetchCustomerData onentry log expr='Customer - Fetching data'/ al:fetchTableData select=['col1', 'col2'] / /onentry /state In the custom action, I am evaluating this string through JEXL Evaluator: public void execute(EventDispatcher eventDispatcher, ErrorReporter errorReporter, SCInstance scInstance, Log log, Collection collection) throws ModelException, SCXMLExpressionException { log.info (scInstance.getEvaluator().eval(scInstance.getRootContext(), this.getSelect())); } This throws an error: WARNING: EXPRESSION_ERROR (eval('['col1', 'col2']'):Encountered [ at line 1, column 1. Was expecting one of: EOF INTEGER_LITERAL ... FLOAT_LITERAL ... { ... empty ... ( ... size ... - ... ~ ... ! ... not ... null ... true ... false ... ; ... if ... while ... foreach ... IDENTIFIER ... STRING_LITERAL ... ): Is creating arrays (or HashMaps, for that matter) even possible like this in SCXML? I was following the guide at: http://commons.apache.org/jexl/reference/syntax.html The executor was created like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new JexlContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); Thank you! snip/ JEXL 2.x syntax will require a suitable Evaluator/Context implementation (the default in v0.9 supports JEXL 1.x). You can either provide one yourself or try the one attached to this ticket [1]. -Rahul [1] https://issues.apache.org/jira/browse/SCXML-114 - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[scxml] Calling go() twice
Hello all, I've just started using SCXML and it's great. However, I've hit a brick wall and I can't seem to figure out something. I have the following XML file: scxml xmlns=http://www.w3.org/2005/07/scxml; version=1.0 initialstate=state1 state id=state1 onentry log expr=State 1/ /onentry transition target=state2 / /state state id=state2 onentry log expr=State 2/ /onentry transition target=state3 cond=1 = 2 / /state state id=state3 final=true onentry log expr=State 3/ /onentry /state /scxml Now, I execute the state machine like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new ELEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new ELContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); // Start execution try { exec.go(); exec.go(); } catch (ModelException e) { e.printStackTrace(); } As you can see I call exec.go() two times. I would expect that in the first time, the state machine will stop in the state2 state and remain there, because condition is not satisfied for going into state3. However, when exec.go() is called the second time, it goes from the start. Effectively, it acts as exec.reset()? Following output is provided: 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 Could you explain this behavior?
Re: [scxml] Calling go() twice
Thanks Jocke. How would you suggest to resume the the last state before the condition was not met? Let's say that the condition was made valid somehow. How to resume from the last state? To continue the previous example: try { exec.go(); // Execution stops at state2, condition is not met // Condition is made valid through some means // How to resume? } catch (ModelException e) { e.printStackTrace(); } 2011/5/3 jocke eriksson joakim.eriks...@albatross.com exec.go(); should only be called once. It will start the state machine and it will go through all steps that meets the criteria (event cond). Regards Jocke. 2011/5/3 Dario D darac1...@gmail.com: Hello all, I've just started using SCXML and it's great. However, I've hit a brick wall and I can't seem to figure out something. I have the following XML file: scxml xmlns=http://www.w3.org/2005/07/scxml; version=1.0 initialstate=state1 state id=state1 onentry log expr=State 1/ /onentry transition target=state2 / /state state id=state2 onentry log expr=State 2/ /onentry transition target=state3 cond=1 = 2 / /state state id=state3 final=true onentry log expr=State 3/ /onentry /state /scxml Now, I execute the state machine like this: SCXMLExecutor exec = null; exec = new SCXMLExecutor(new ELEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); Context ctx = new ELContext(); exec.setRootContext(ctx); exec.setStateMachine(scxml); exec.setSuperStep(true); // Start execution try { exec.go(); exec.go(); } catch (ModelException e) { e.printStackTrace(); } As you can see I call exec.go() two times. I would expect that in the first time, the state machine will stop in the state2 state and remain there, because condition is not satisfied for going into state3. However, when exec.go() is called the second time, it goes from the start. Effectively, it acts as exec.reset()? Following output is provided: 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 1 03.05.2011. 14:01:32 org.apache.commons.scxml.model.Log execute INFO: null: State 2 Could you explain this behavior? -- Joakim Eriksson Albatross Holländargatan 20, 111 60 Stockholm Sweden +46 8 51160773 | Mobile +46 708 507 480 joakim.eriks...@albatross.com | www.albatross.com - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org