locked
Using Events as a trigger to change states in a state machine model RRS feed

  • Question

  • I am trying to model an state machine for a client that communicates with a server, receive some data and update the interface.

     

    This client has to update indefinitely, and at a unsuccessful attempt to connect to the server it will change to the re-acquiring connection state, where it tries after X seconds to reconnect.

    I managed to get that behavior up and running. I can repeatability call update, and detect when a connection was lost. I'm also able to update the interface, disabling some controls and letting the user know that the connection was lost and that a reconnection attempt will occur every X seconds. The reconnection behavior is also ok, i can detect when a reconnection was made, change the interface accordingly and i'm able to change to the update state again.

     

    The problem lies in another requirement: After a successful update i need to check if the user is giving an input, so i can stop updating until the user finishes using the interface and them start updating again.

    I need to have this sort of control because the client gathers some 3d models from the server and after each update has to recompile the models whose vertex where altered, and that operation is a little lengthy causing the UI to become really unresponsive.

    I already have the logic for stop the update running, the user can manipulate the objects directly from a viewport or through some ui buttons, but i'm not using wwf. Currently my application does not support reconnection though, and i would like to use wwf for that so the update/reconnection behavior can be easily modified.

    The problem is, everywhere i looked uses bookmarks to send data to the workflow. The problem is this approach pauses the workflow until the caller resumes the bookmark, which is not the behavior i'm looking for. I think i could loop to update and afterwards check for a condition, but i don't know how to send that data after the workflow started.

    Or is there any event handling on wwf without the need to pause the workflow to receive it?

     

    Thank you!

    Wednesday, March 16, 2011 3:25 PM

Answers

  • I imagine you could model the events in your workflow something like this:

    state 1: waiting for compilation [in background] to finish
    event 1: compilation finishes, transition to state 2
    event 2: user cancels, cancel compilation background work, transition to state 3
    event 3: receive update message from server...

    Notice in that case the compilation 'work' isn't really happening in the workflow at all, it's happening somewhere else, the workflow is just being used to model a controller process.

    Notice with this way of doing things, the 'UI interaction', where someone presses a button in the UI, is also something external to the workflow.

    And yes, the workflow is paused while it is waiting for events. But that should be OK, I think. Because it doesn't need to mean your UI is paused.

    Tim

    • Marked as answer by Andrew_Zhu Wednesday, March 23, 2011 1:47 AM
    Thursday, March 17, 2011 4:12 PM