Announcement Announcement Module
Collapse
No announcement yet.
Transition to continuation/snapshotted view state? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transition to continuation/snapshotted view state?

    Can SWF be used to handle transitions to a continuation/snapshot of a state?

    Suppose I have a flow that looks like this: A->B->C->D

    The user has navigated from A to B to C to D so there exist continuations for A, B, C, and D. I would like to be able to configure a transition that means "restore the most recent continuation for state B".

    It could look something like this:
    <transition on="GoBack" to-continuation="<B"/>

    In this case going back skips state C.

    In addition to this I need to be able to specify other relative paths to snapshots, such as: back n snapshots, back n snapshots of a specific state, last occurrence of state, etc.

    I'd need some advice on how best to customize SWF to handle transitions from a state to a continuation/snapshot of a state because I can't see an easy way to do this.

  • #2
    The ContinuationFlowExecutionRepository will store snapshots of the flow and in theory they can be restored. However, I don't think there is anything that ties the snapshoted continuations to a specific flow i.e. nothing that says this snapshot is at the point B.

    It is not unthinkable that you could store this map of continuation keys to the actual state somewhere to allow you to go back to the last version of B. But I don't think this is done out of the box by SWF.

    I can see this being useful for a breadcrumbs style menu.

    Disclaimer: I am not an expert on SWF so don't take this as the word of god, aka Erwin/Kieth

    Comment


    • #3
      SWF doesn't provide this kind of functionality out of the box.

      Toppac already gave some good tips.
      My advice would basically be:
      - Study in-depth how SWF handles continuations by looking at classes like the FlowExecutorImpl and ContinuationFlowExecutionRepository.
      - Then figure out how best to customize this to add the stuff you need.

      Plugging in a custom FlowExecutor implementation or FlowExecutionRepository implementation is easy, so once you have those you should be set.

      Erwin

      Comment


      • #4
        I would like to have a transition that's configured like this:
        <transition on="GoBack" to="continuation:../viewA"/> <!-- go back to last snapshot of viewA -->


        Attempt #1
        calling RequestContext.signalEvent ultimately results in the matching Transition executing
        however, there does not appear to be an easy way to extend Transition to support
        parsing continuation: type stateIds and resolving them to stored FlowExecutions that can be refreshed.
        What would it take to modify Transition? Would I have to write a new FlowBuilder?

        Attempt #2
        I started down the path of trying to get the Transition details from within the FlowExecutor.resume
        method so that I could decide whether or not to restore a FlowExecution from the Repository before calling
        flowExeuction.signalEvent, but doing so appears to require me to rewrite RequestControlContextImpl (because
        it is only visible to FlowExecutionImpl) and due
        to protected access consequently FlowExecutionImpl. This seems like too much work, not to mention risk
        as the framework evolves.

        Here's the code inside MyFlowExecutor.resume

        HTML Code:
                FlowExecution flowExecution = executionRepository.getFlowExecution(key);
        
                        StateDefinition state = flowExecution.getActiveSession().getState();
                        if (state instanceof ViewState) {
                            ViewState viewState = (ViewState) state;
                            RequestContext requestContext = new RequestControlContextImpl(this, context);
        
                            Transition transition = viewState.getTransitionSet().getTransition(requestContext);
                            String targetStateId = transition.getTargetStateId();
                            if (targetStateId.startsWith("continuation:"))
                            {
                                String continuationPath = targetStateId;
                                // if this starts with "continuation:" search for a continuation in the repository and refresh it.
                                executionRepository.getRelativeFlowExecution(key, continuationPath).refresh(context);
                            }
                        }

        I think creating the custom ContinuationFlowExecutionRepository will be no problem, but I'm stuck trying to figure
        out how to tie continuation type transitions into the execution flow.

        To me it makes most sense to have this happen at the Transition level. This will allow maximum reuse of
        the existing framework for firing events and maintaining consistent state.
        However, for this to work the Transition will probably need to have access to the FlowExecutor and Repository.

        I'm not even sure this makes sense. Perhaps somebody else has written a custom FlowExecutor I can look at? I'd love
        some more tips ideas about how to have a transition result in a FlowExecution.refresh rather than a State.enter.

        I would also like an opinion about whether this functionality can or should be tacked onto the side of SWF or is more likely to require deeper changes to SWF itself.

        Please help. Thanks in advance.

        Comment


        • #5
          but I'm stuck trying to figure
          out how to tie continuation type transitions into the execution flow.
          You've got a bit of a chicking-and-egg problem here. When the transition executes, you're *inside* a flow execution. At that point you've already loaded the continuation snapshot you're working from and you cannot just 'change that'. So you'll have to jump out of the flow and come back in, loading the correct continuation along the way (similar to a redirect or externalRedirect).

          I'd love
          some more tips ideas about how to have a transition result in a FlowExecution.refresh rather than a State.enter.
          Take a look a the FlowExecutionRedirect view selection class.

          My guess would be that it's possible to do this.
          If you can't get it working and it's crucial to your application, you can always consider contracting somebody to prototype a solution.

          Erwin

          Comment

          Working...
          X