How do you represent an asynchronous action that can modify the program state in a statechart?

StackOverflow https://stackoverflow.com/questions/19814975

  •  04-07-2022
  •  | 
  •  

Question

I have an action that does 2 things, first it will change the application state and second it makes a call out to a webservice. When the webservice sends it's response, it will affect the current application state.Example statechart

Lets say I have the above setup. Method1() calls the webservice and causes the state to change from A to B. After the Method1() call up to the Finish() call, the status can change from B to C, B to Success, etc..

If B changes to Success, it could also then change from Success to C.

How would I tie in the Success and Fail states when the state can be set at any point after the Method1() action?

Was it helpful?

Solution

I am not sure to really understood your whole issue but for designing your problem I would use events. A transition can be trigger when an event occurs so I would create an "ReceiveResponse" event and a transition between state B and the decision Node (as depicted below). This models the fact that if you state machine is in state B and receive a response the transition is triggered and will, according to the value of the response, change is status from B to Success or Fail.

Modelio state machine

Maybe could you describe a little more the possible transition or state possible? Is it possible for your object to be in two state at the same time?

Hoping it helps,

EBR

OTHER TIPS

I would recommend using a sequence diagram.

  1. Sequence diagrams allow for async calls of class/component methods. (or http requests handled by a thing represented as a method) This is really what you need. You would have the sequence diagram focus on their being multiple control flows to achieve a certain result.

  2. State diagrams are really quite low level and might map to this domain poorly. However, if you must, all of your methods/interactions must be recast as state changes, NOT, calls. A state machine moved between states, not methods and classes. So your state transitions would have to be "receive message of B with value A". Not what you are going for I suspect. It would not really help me understand your system.

  3. If you need to do this because you are doing MDA/Generative UML then expand on your question greatly. I am assuming this is a basic UML question, if not let me know and I can add more details.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top