/**
  * Remove a ReliantContinuationState from the top SeqContinuationState in the stack. This should
  * be done when returning back from a sub branch of a FlowContinuableMediator.
  *
  * @param synCtx MessageContext
  */
 public static void removeReliantContinuationState(MessageContext synCtx) {
   if (synCtx.isContinuationEnabled()) {
     if (!synCtx.getContinuationStateStack().isEmpty()) {
       ContinuationState seqContState = synCtx.getContinuationStateStack().peek();
       seqContState.removeLeafChild();
     } else {
       // Ideally we should not get here.
       log.warn("Continuation Stack is empty. Probably due to a configuration issue");
     }
   }
 }
Esempio n. 2
0
  public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);

    if (synLog.isTraceOrDebugEnabled()) {
      synLog.traceOrDebug("Invoke mediator : Mediating from ContinuationState");
    }

    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();

    if (subBranch == 0) {
      // Default flow
      TemplateMediator templateMediator =
          (TemplateMediator) synCtx.getSequenceTemplate(targetTemplate);

      if (!continuationState.hasChild()) {
        result = templateMediator.mediate(synCtx, continuationState.getPosition() + 1);
        if (result) {
          templateMediator.popFuncContextFrom(synCtx);
        }
      } else {
        FlowContinuableMediator mediator =
            (FlowContinuableMediator) templateMediator.getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
      }
    } else {
      // Pre fetching invoke mediator flow
      String prefetchInvokeKey = key.evaluateValue(synCtx);
      InvokeMediator prefetchInvoke =
          (InvokeMediator) synCtx.getDefaultConfiguration(prefetchInvokeKey);

      ContinuationState childContinuationState = continuationState.getChildContState();
      result = prefetchInvoke.mediate(synCtx, childContinuationState);

      if (result && !childContinuationState.hasChild()) {
        // Pre fetching invoke mediator flow completed.
        // Remove ContinuationState represent the prefetchInvoke mediator and
        // flip the subbranch to default flow
        continuationState.removeLeafChild();
        ((ReliantContinuationState) continuationState).setSubBranch(0);
        // after prefetch invoke mediator flow, execute default flow
        result = mediate(synCtx, false);
      }
    }
    return result;
  }