Re: [SCXML] getting set datats in the datamodel
On Mon, Apr 27, 2009 at 10:05 AM, Anna Södling anna.sodl...@passagen.se wrote: Hi, Is there anyone who has any idea what to do about this? Even a little hint would be appreciated, you don't have to solve the whole problem! snip/ Reply inline below. /Linda -Ursprungligt Meddelande- From: Linda Erlenhov [u...@commons.apache.org] Sent: 23/4/2009 2:30:58 PM To: Commons Users List Subject: Re: [SCXML] getting set datats in the datamodel Hello again! This seems to work, since we now can see that data has changed. Unfortunately, we seem to have missed out an important part of the question. In addition to being notified when a data value is set, we also would like to be able to get/recieve the new data value aswell as the name (in this case numdat) so that we can display it to the screen in our interface. And, in this example we only have one data value, NumDat. However, it is possible to define several data values insade the DynamicData-tag. Can we still just write assign name=DynamicData expr=DynamicData/ after the first assign tag, or do we also have to define what data value has been changed? snap/ You will find that as more and more of the application-specific patterns (and requirements) emerge, it is convenient to encapsulate these patterns as custom actions (perhaps a time to rethink the no custom action constraint). Without that, you could always store the name (lets call it 'delta', which signifies that it identifies the change) in the root context, update it with every assign as needed and look it up for your notifications, so along these lines (continuing example from earlier in this thread): scxml ... datamodel data name=delta / /datamodel state ... onentry !-- assignment below taken from example above -- assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ !-- followed by assignment that triggers the set call with the new value -- assign name=DynamicData expr=DynamicData/ !-- store the delta for use in notifications -- assign name=delta expr='NumDat'/ /onentry ... /state ... /scxml and the Context#set() method previously discussed would then change along these lines: public void set(String name, Object value) { // inherit behavior super.set(name, value); // notifications you need // the second param is the new info needed notify(name, get(delta), value); } Now, OTOH, all of this can really be distilled into a compact custom action such as: my:assign data=DynamicData location=NumDat expr=Data(DynamicData,'NumDat')+1/ whose implementation encapsulates the pattern of updates and notifications as needed by the application and thereby leaves the markup cleaner. -Rahul Sincerely, Linda snip/ Yup, I see what you are running into. Unfortunately for the specific usage pattern here, the two assign variations have different semantics as follows: 1) assign name=... expr=.../ is a set operation, which produces a Context#set(...) call 2) assign location=... expr=.../ is really a mutation operation, it retrieves the XML data tree (stored as a DOM node in memory) and manipulates it -- there is no call to Context#set(...) How do I notify when my DynamicData has changed? snap/ ISTR that you prefer to not use custom actions. With those constraints, one option (since you are generating all the SCXML) is to accomodate for the above variation via the SCXML markup itself -- so you could generate a redundant identity assignment to trigger the Context#set(...) call like so: !-- assignment below taken from example above -- assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ !-- followed by assignment that triggers the set call with the new value -- assign name=DynamicData expr=DynamicData/ -Rahul - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] getting set datats in the datamodel
Hello again! This seems to work, since we now can see that data has changed. Unfortunately, we seem to have missed out an important part of the question. In addition to being notified when a data value is set, we also would like to be able to get/recieve the new data value aswell as the name (in this case numdat) so that we can display it to the screen in our interface. And, in this example we only have one data value, NumDat. However, it is possible to define several data values insade the DynamicData-tag. Can we still just write assign name=DynamicData expr=DynamicData/ after the first assign tag, or do we also have to define what data value has been changed? Sincerely, Linda snip/ Yup, I see what you are running into. Unfortunately for the specific usage pattern here, the two assign variations have different semantics as follows: 1) assign name=... expr=.../ is a set operation, which produces a Context#set(...) call 2) assign location=... expr=.../ is really a mutation operation, it retrieves the XML data tree (stored as a DOM node in memory) and manipulates it -- there is no call to Context#set(...) How do I notify when my DynamicData has changed? snap/ ISTR that you prefer to not use custom actions. With those constraints, one option (since you are generating all the SCXML) is to accomodate for the above variation via the SCXML markup itself -- so you could generate a redundant identity assignment to trigger the Context#set(...) call like so: !-- assignment below taken from example above -- assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ !-- followed by assignment that triggers the set call with the new value -- assign name=DynamicData expr=DynamicData/ -Rahul
Re: [SCXML] getting set datats in the datamodel
On Wed, Apr 22, 2009 at 9:35 AM, Linda Erlenhov linda.erlen...@gmail.com wrote: Hello Is there anybody that can help me with my problem described below? best regards //Linda On Mon, Apr 20, 2009 at 2:05 PM, Linda Erlenhov linda.erlen...@gmail.comwrote: Hello I think I´ve done some mixing between two things that doesn´t work together as I hoped it would. I have this Datamodel, the scxml document starts like this: scxml version=1.0 initialstate=INIT xmlns:cs= http://commons.apache.org/scxml; xmlns=http://www.w3.org/2005/07/scxml; datamodel data name=DynamicData NumDat xmlns= id=1 type=Integer0/NumDat /data data name=Indication1 expr=false/ /datamodel snip/- I assign the Indication1 later on: --- state id=StateC onentry log label=Renegade expr='Entering state: StateC'/ assign name=Indication1 expr=true/ /onentry snip/--- And the DynamicData also later: --- state id=StateB onentry log label=Renegade expr='Entering state: StateB'/ log label=Renegade expr=Data(DynamicData,'NumDat')/ assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ log label=Renegade expr=Data(DynamicData,'NumDat')/ /onentry snip/--- I implemented a custom context with a notification functionality in the set function (observer observed pattern) but the problem now is that the only time the set function in the context is used is when indications are set. Not when the DynamicData is set. I know that the SCXML works and that the expressions evaluate properly because of the log:labels, my guess is that it´s something with the Data() function that makes these expressions do something different. What? Where is the set for the DynamicData located? snip/ Yup, I see what you are running into. Unfortunately for the specific usage pattern here, the two assign variations have different semantics as follows: 1) assign name=... expr=.../ is a set operation, which produces a Context#set(...) call 2) assign location=... expr=.../ is really a mutation operation, it retrieves the XML data tree (stored as a DOM node in memory) and manipulates it -- there is no call to Context#set(...) How do I notify when my DynamicData has changed? snap/ ISTR that you prefer to not use custom actions. With those constraints, one option (since you are generating all the SCXML) is to accomodate for the above variation via the SCXML markup itself -- so you could generate a redundant identity assignment to trigger the Context#set(...) call like so: !-- assignment below taken from example above -- assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ !-- followed by assignment that triggers the set call with the new value -- assign name=DynamicData expr=DynamicData/ -Rahul - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] getting set datats in the datamodel
Hello I think I´ve done some mixing between two things that doesn´t work together as I hoped it would. I have this Datamodel, the scxml document starts like this: scxml version=1.0 initialstate=INIT xmlns:cs= http://commons.apache.org/scxml; xmlns=http://www.w3.org/2005/07/scxml; datamodel data name=DynamicData NumDat xmlns= id=1 type=Integer0/NumDat /data data name=Indication1 expr=false/ /datamodel snip/- I assign the Indication1 later on: --- state id=StateC onentry log label=Renegade expr='Entering state: StateC'/ assign name=Indication1 expr=true/ /onentry snip/--- And the DynamicData also later: --- state id=StateB onentry log label=Renegade expr='Entering state: StateB'/ log label=Renegade expr=Data(DynamicData,'NumDat')/ assign location=Data(DynamicData,'NumDat') expr=Data(DynamicData,'NumDat')+1/ log label=Renegade expr=Data(DynamicData,'NumDat')/ /onentry snip/--- I implemented a custom context with a notification functionality in the set function (observer observed pattern) but the problem now is that the only time the set function in the context is used is when indications are set. Not when the DynamicData is set. I know that the SCXML works and that the expressions evaluate properly because of the log:labels, my guess is that it´s something with the Data() function that makes these expressions do something different. What? Where is the set for the DynamicData located? How do I notify when my DynamicData has changed? Best regards Linda
Re: [SCXML] getting set datats in the datamodel
On Wed, Apr 15, 2009 at 12:34 PM, Linda Erlenhov linda.erlen...@gmail.com wrote: Hello So I´m back here again. My problem now is that I don´t know how to notify. I looked at the solution suggested below since I thought it would be the easiest and best looking way to implement this. The way my first solution worked was to use Observer and Observable. Since Observable is a class I could not extend SimpleContext aswell (since multiple inheritance from classes is not ok in java) so i just copied SimpleContext instead since it only implemented two Interfaces, extended Observable and modifyed it according to my liking. snip/ I'd do it the other way, extend the Context implementation and add observable functionality since I claim the latter is the simpler bit (lower case o here, not referring to the java.util class -- minimally, (a) maintain a list of observers as an instance field, (b) have an adder method that adds observers to the list and (c) have the notify method in question iterate over the observers to notify them of the value change). The problem then was that to user timers (as I was asking about in another thread) and they use JEXL. So to make the timers work I have to use an JEXL or JEXL extended class. And there goes my Observable. snap/ Timers don't need JEXL, you can continue using whatever EL you were using (extend the corresponding Context and Evaluator implementations -- if you were in fact using Commons JEXL, you'd extend JexlContext and JexlEvaluator and so on). I am aware that this might be a java question instead of a SCXML question and if so I apologise. Maybe you can see something that I have missed or help me with where I should post this question. I´ve stared a bit too long at my code by now. Is there another way to do this? snip/ Its a bit more of a Java question than an SCXML question, yes. You could post to any Java forums / try search engines. -Rahul best regards //Linda * Use a custom Context implementation - This will allow you to intercept data changes, à la pointcut at oacs.Context#set(String,Object), and get notifications that way This could possibly be of intrest, but I´m still not 100% sure on how the context works. Where would these notifications arrive snip/ This is another approach, some background: http://commons.apache.org/scxml/guide/contexts-evaluators.html I'll sketch an outline here -- say we have MyContext extending SimpleContext where MyContext#set(String,Object) looks like: public void set(String name, Object value) { // inherit behavior super.set(name, value); // notifications you need notify(name, value); } and a MyEvaluator extending the Evaluator you are currently using whose newContext() method does this: public Context newContext(Context parent) { return new MyContext(parent); } then using this evaluator with the SCXMLExecutor instances like so: SCXMLExecutor exec = new SCXMLExecutor(); ... exec.setEvaluator(new MyEvaluator()); ties in the above pointcut behavior causing notifications for any data changes within the state machine. Adjust outline per requirements. -Rahul best regards //Linda - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] getting set datats in the datamodel
On Mon, Apr 6, 2009 at 10:35 AM, Linda Erlenhov linda.erlen...@gmail.com wrote: Hello again! I´m not sure how to explain what I want to do. snip/ Code snippets like the ones below help. The task I have is to build an editor that you then can use to build simulations of applications. An application can be a cd-player for instance. What already exists is an editor for building GUI:s without coding (not build by me) and an engine that runs this and via a protocol talks to an application. What I´m trying to do is attatch my editor to the protocol instead of a real life application. The problem is that I´m developing this very generic. I can not know what kind of application the user want to simulate, the only thing I have to run this from is the protocol specification and in that specification it, for one thing, says that I should be able to handle dynamic data subscriptions. In the cd-player case this could be that a track on the cd has ended and a new has begun, if I have an subscription for the title of the song playing I would then like to send it to the engine i was talking about. So if I write a datamodel like (well, I don´t, it would be generated like this): data name=Data Title id=1 type=Stringtext/Title Track id=4 type=Integer0/Track /data snap/ OK. What location in the SCXML document do you generate this datamodel? I previously suggested its easiest if this appears as child of root (you can use the stock Contexts and Evaluators): http://markmail.org/message/bt3oli33cey7ecju and then somewhere in the scema the person who build the simulation wants title to change, this is then translated to: assign location=Data.title expr=oh yeah! / as an example. snip/ For an XML data model, its best to use the XPath Evaluator (though its yet unreleased), where the above would look like: assign location=$Data/title expr=oh yeah! / Or use the Data() function with other Evaluators, see this page for details: http://commons.apache.org/scxml/guide/datamodel.html Moreover, since you are in control of the generated markup, you could generate a custom action to do the notifications for you. More on custom actions here: http://commons.apache.org/scxml/guide/custom-actions.html So, for example, instead of generating: assign location=$Data/title expr=oh yeah! / you could generate: my:assign location=$Data/title expr=oh yeah! / where custom action my:assign inherits from standard action assign to do the extra notifications bit. If i want to read what data.title:s expression is, how do I do that? I used the: http://www.ling.gu.se/~lager/Labs/SCXML-Lab/ for more examples, I´m not sure if you´re using the same standard, but it´s an easy way to understand how the SCXML works. snap/ Same, but the expression language in use isn't the same, the XML data model seems to be shredded into an ECMA friendly variant. Hence the difference in the expression above. * Use a custom Context implementation - This will allow you to intercept data changes, à la pointcut at oacs.Context#set(String,Object), and get notifications that way This could possibly be of intrest, but I´m still not 100% sure on how the context works. Where would these notifications arrive snip/ This is another approach, some background: http://commons.apache.org/scxml/guide/contexts-evaluators.html I'll sketch an outline here -- say we have MyContext extending SimpleContext where MyContext#set(String,Object) looks like: public void set(String name, Object value) { // inherit behavior super.set(name, value); // notifications you need notify(name, value); } and a MyEvaluator extending the Evaluator you are currently using whose newContext() method does this: public Context newContext(Context parent) { return new MyContext(parent); } then using this evaluator with the SCXMLExecutor instances like so: SCXMLExecutor exec = new SCXMLExecutor(); ... exec.setEvaluator(new MyEvaluator()); ties in the above pointcut behavior causing notifications for any data changes within the state machine. Adjust outline per requirements. -Rahul best regards //Linda - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] getting set datats in the datamodel
Hello Armel Me and another girl named Anna has build the editor using GMF, Graphical modeling framework for Eclipse (http://www.eclipse.org/modeling/gmf/) as a part of our Master Thesis project. best regards //Linda On Fri, Apr 3, 2009 at 11:59 AM, Armel SORO armel.soro.sc...@gmail.comwrote: Hi Linda, This is not really an answer to the problem but a simple question: which kind of graphical editor do you use to build state machines? Was it built from scratch or did you use any specific software to do this? I am indeed interesting in using one like that to model my system and generate the corresponding SCXML document. B.R. -- Armel 2009/3/31 Linda Erlenhov linda.erlen...@gmail.com Hello again! I have a problem with my datamodel. Or rather the fetching of datas that are used in the datamodel. I have my editor for building statemachines graphical, this is then translated into a corresponding SCXML document that then is run normally with Apache commons. The person that uses the editor shoul amongst other things be able select if she/he has want´s some data to be set (integers or strings) when entering states. The GUI that communicates with the machine does this via an interface wich is the thing I´m writing now. The GUI can send subscriptions requests for data wich basically means that it wants to subscribe certain data and wants the interface to send it when the data is changed. How I solved the part of saving checking the data is somewhat irrelevant, the problem is when I want to fetch the data that is saved. Since the model doesn´t tell when data has changed I check whenever entering a state (onEntry Listner) but where do I check this. Where is this, the data, saved? best regards //Linda
Re: [SCXML] getting set datats in the datamodel
Hello again! I´m not sure how to explain what I want to do. The task I have is to build an editor that you then can use to build simulations of applications. An application can be a cd-player for instance. What already exists is an editor for building GUI:s without coding (not build by me) and an engine that runs this and via a protocol talks to an application. What I´m trying to do is attatch my editor to the protocol instead of a real life application. The problem is that I´m developing this very generic. I can not know what kind of application the user want to simulate, the only thing I have to run this from is the protocol specification and in that specification it, for one thing, says that I should be able to handle dynamic data subscriptions. In the cd-player case this could be that a track on the cd has ended and a new has begun, if I have an subscription for the title of the song playing I would then like to send it to the engine i was talking about. So if I write a datamodel like (well, I don´t, it would be generated like this): data name=Data Title id=1 type=Stringtext/Title Track id=4 type=Integer0/Track /data and then somewhere in the scema the person who build the simulation wants title to change, this is then translated to: assign location=Data.title expr=oh yeah! / as an example. If i want to read what data.title:s expression is, how do I do that? I used the: http://www.ling.gu.se/~lager/Labs/SCXML-Lab/ for more examples, I´m not sure if you´re using the same standard, but it´s an easy way to understand how the SCXML works. This still is all quite vague to me -- for example, not clear where you put the data in the first place. If you want to listen to data changes, listening to state changes may not be the way to proceed (so I wouldn't use SCXMLListener for this purpose). I can think of multiple potential options: * Avoid the need for any data synchronization / subscriptions altogether - Back the state machine's root context with the actual data store Unfortunently this is not an option because the parts that use the subscriptions are not written by me and already exists, I just want to communicate with these parts. * Declaratively add transitions guarded on specific *.change events - Has the benefit of capturing the associated actions in the SCXML document itself (use the appropriate executable content on transition) Not sure how this would work for the user of my editor. * Use a custom Context implementation - This will allow you to intercept data changes, à la pointcut at oacs.Context#set(String,Object), and get notifications that way This could possibly be of intrest, but I´m still not 100% sure on how the context works. Where would these notifications arrive best regards //Linda
Re: [SCXML] getting set datats in the datamodel
Hi Linda, This is not really an answer to the problem but a simple question: which kind of graphical editor do you use to build state machines? Was it built from scratch or did you use any specific software to do this? I am indeed interesting in using one like that to model my system and generate the corresponding SCXML document. B.R. -- Armel 2009/3/31 Linda Erlenhov linda.erlen...@gmail.com Hello again! I have a problem with my datamodel. Or rather the fetching of datas that are used in the datamodel. I have my editor for building statemachines graphical, this is then translated into a corresponding SCXML document that then is run normally with Apache commons. The person that uses the editor shoul amongst other things be able select if she/he has want´s some data to be set (integers or strings) when entering states. The GUI that communicates with the machine does this via an interface wich is the thing I´m writing now. The GUI can send subscriptions requests for data wich basically means that it wants to subscribe certain data and wants the interface to send it when the data is changed. How I solved the part of saving checking the data is somewhat irrelevant, the problem is when I want to fetch the data that is saved. Since the model doesn´t tell when data has changed I check whenever entering a state (onEntry Listner) but where do I check this. Where is this, the data, saved? best regards //Linda
Re: [SCXML] getting set datats in the datamodel
For the archives, the discussion below has moved to ongoing thread titled [SCXML] History state. -Rahul On Thu, Apr 2, 2009 at 5:07 PM, Ouyang, Landon - ES/RDR -Gil landon.ouy...@itt.com wrote: I am trying to implement a history state. It does work, returns to the calling state, however it enters all the super states before getting to the calling state. Which also calls entry actions (when there are entry actions). This is not the behavior I was expecting. Can you explain to me how to prevent this? Below is the command line output from a small program that accepts trigger events and has a listener attached to the states that outputs the current state. [spalmis...@linuxserver src]$ run.sh Default scxml file is: HistoryTest.scxml Enter path to over-ride (or enter to continue): triggerTO_STATE12 In State12 triggerTO_STATE32 In State3 In State32 triggerSTATE32_TO_HISTORY In TopState (This is what I don't want!!) In State1 (This is what I don't want!!) In State12 (This is what I do want) trigger SCXML file used: ?xml version=1.0? scxml xmlns=http://www.w3.org/2005/07/scxml; xmlns:my=http://www.company.com; xmlns:uml=http://schema.omg.org/spec/UML/2.1.1; xmlns:xmi=http://schema.omg.org/spec/XMI/2.1; version=1.0 initial=StateMachineInitial state id=TopState state id=State3 state id=State31 transition event=STATE31_TO_HISTORY target=S1History/ /state state id=State32 transition event=STATE32_TO_HISTORY target=S1History/ /state initial id=State3Initial transition target=State31/ /initial /state initial id=TopStateInitial transition target=State1/ /initial state id=State1 state id=State12 transition event=TO_STATE32 target=State32/ transition event=TO_STATE11 target=State11/ /state state id=State11 transition event=TO_STATE31 target=State31/ transition event=TO_STATE12 target=State12/ /state history id=S1History type=deep transition target=State11/ /history initial id=S1Initial transition target=State11/ /initial /state transition event=END target=StateMachineFinal/ /state state id=StateMachineInitial transition target=TopState/ /state final id=StateMachineFinal/ /scxml -- Landon Ouyang Senior Design Engineer ITT Electronics Systems, Radar Systems - Gilfillan 7821 Orion Ave, Van Nuys, CA 91406 (818) 901-2982 This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] getting set datats in the datamodel
On Tue, Mar 31, 2009 at 7:46 AM, Linda Erlenhov linda.erlen...@gmail.com wrote: Hello again! I have a problem with my datamodel. Or rather the fetching of datas that are used in the datamodel. I have my editor for building statemachines graphical, this is then translated into a corresponding SCXML document that then is run normally with Apache commons. The person that uses the editor shoul amongst other things be able select if she/he has want´s some data to be set (integers or strings) when entering states. The GUI that communicates with the machine does this via an interface wich is the thing I´m writing now. The GUI can send subscriptions requests for data wich basically means that it wants to subscribe certain data and wants the interface to send it when the data is changed. How I solved the part of saving checking the data is somewhat irrelevant, the problem is when I want to fetch the data that is saved. Since the model doesn´t tell when data has changed I check whenever entering a state (onEntry Listner) but where do I check this. Where is this, the data, saved? snip/ This still is all quite vague to me -- for example, not clear where you put the data in the first place. If you want to listen to data changes, listening to state changes may not be the way to proceed (so I wouldn't use SCXMLListener for this purpose). I can think of multiple potential options: * Avoid the need for any data synchronization / subscriptions altogether - Back the state machine's root context with the actual data store * Declaratively add transitions guarded on specific *.change events - Has the benefit of capturing the associated actions in the SCXML document itself (use the appropriate executable content on transition) * Use a custom Context implementation - This will allow you to intercept data changes, à la pointcut at oacs.Context#set(String,Object), and get notifications that way -Rahul best regards //Linda - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org