Search in sources :

Example 6 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator in project wso2-synapse by wso2.

the class InvokeMediator method mediate.

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();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    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());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
        if (isStatisticsEnabled) {
            templateMediator.reportCloseStatistics(synCtx, null);
        }
    } 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);
        }
        if (isStatisticsEnabled) {
            prefetchInvoke.reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) ContinuationState(org.apache.synapse.ContinuationState) ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState)

Example 7 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator in project wso2-synapse by wso2.

the class AggregateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState contState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Aggregate mediator : Mediating from ContinuationState");
    }
    boolean result;
    SequenceMediator onCompleteSequence = getOnCompleteSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!contState.hasChild()) {
        result = onCompleteSequence.mediate(synCtx, contState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) onCompleteSequence.getChild(contState.getPosition());
        result = mediator.mediate(synCtx, contState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        onCompleteSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 8 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator in project wso2-synapse by wso2.

the class SequenceMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (sequenceType == SequenceType.NAMED) {
        CustomLogSetter.getInstance().setLogAppender(artifactContainerName);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Mediating using the SeqContinuationState type : " + ((SeqContinuationState) continuationState).getSeqType() + " name : " + ((SeqContinuationState) continuationState).getSeqName());
    }
    Mediator errorHandlerMediator = null;
    // push the errorHandler sequence into the current message as the fault handler
    if (errorHandler != null) {
        errorHandlerMediator = synCtx.getSequence(errorHandler);
        if (errorHandlerMediator != null) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Setting the onError handler : " + errorHandler + " for the sequence : " + name);
            }
            synCtx.pushFaultHandler(new MediatorFaultHandler(errorHandlerMediator));
        } else {
            synLog.auditWarn("onError handler : " + errorHandler + " for sequence : " + name + " cannot be found");
        }
    }
    boolean result;
    if (!continuationState.hasChild()) {
        result = super.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        // if children exists first mediate from them starting from grandchild.
        do {
            FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (RuntimeStatisticCollector.isStatisticsEnabled()) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
            if (result) {
                // if flow completed remove leaf child
                continuationState.removeLeafChild();
            }
        } while (result && continuationState.hasChild());
        if (result) {
            // after mediating from children, mediate from current SeqContinuationState
            result = super.mediate(synCtx, continuationState.getPosition() + 1);
        }
    }
    if (result) {
        // if flow completed, remove top ContinuationState from stack
        ContinuationStackManager.popContinuationStateStack(synCtx);
    }
    // before we exit normally without an exception
    if (errorHandlerMediator != null) {
        Stack faultStack = synCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            Object o = faultStack.peek();
            if (o instanceof MediatorFaultHandler && errorHandlerMediator.equals(((MediatorFaultHandler) o).getFaultMediator())) {
                faultStack.pop();
            }
        }
    }
    return result;
}
Also used : SeqContinuationState(org.apache.synapse.continuation.SeqContinuationState) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator) Stack(java.util.Stack)

Example 9 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator in project wso2-synapse by wso2.

the class CloneMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Clone mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    SequenceMediator branchSequence = targets.get(subBranch).getSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!continuationState.hasChild()) {
        result = branchSequence.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) branchSequence.getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        branchSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 10 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator in project wso2-synapse by wso2.

the class IterateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Iterate mediator : Mediating from ContinuationState");
    }
    boolean result;
    SequenceMediator branchSequence = target.getSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!continuationState.hasChild()) {
        result = branchSequence.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) branchSequence.getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        branchSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Aggregations

FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)11 Mediator (org.apache.synapse.Mediator)10 SynapseLog (org.apache.synapse.SynapseLog)10 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)6 ReliantContinuationState (org.apache.synapse.continuation.ReliantContinuationState)5 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)5 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)5 Stack (java.util.Stack)1 ContinuationState (org.apache.synapse.ContinuationState)1 AnonymousListMediator (org.apache.synapse.config.xml.AnonymousListMediator)1 SeqContinuationState (org.apache.synapse.continuation.SeqContinuationState)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 ListMediator (org.apache.synapse.mediators.ListMediator)1 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)1