Search in sources :

Example 1 with ReliantContinuationState

use of org.apache.synapse.continuation.ReliantContinuationState in project wso2-synapse by wso2.

the class FilterMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Filter mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (subBranch == 0) {
        if (!continuationState.hasChild()) {
            result = super.mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
    } else {
        if (!continuationState.hasChild()) {
            result = elseMediator.mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) elseMediator.getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
        if (isStatisticsEnabled) {
            elseMediator.reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) ListMediator(org.apache.synapse.mediators.ListMediator) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator)

Example 2 with ReliantContinuationState

use of org.apache.synapse.continuation.ReliantContinuationState in project wso2-synapse by wso2.

the class SwitchMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Switch mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    if (subBranch == 0) {
        if (!continuationState.hasChild()) {
            result = defaultCase.getCaseMediator().mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) defaultCase.getCaseMediator().getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (RuntimeStatisticCollector.isStatisticsEnabled()) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
    } else {
        if (!continuationState.hasChild()) {
            result = cases.get(subBranch - 1).getCaseMediator().mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) cases.get(subBranch - 1).getCaseMediator().getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (RuntimeStatisticCollector.isStatisticsEnabled()) {
                ((Mediator) mediator).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)

Example 3 with ReliantContinuationState

use of org.apache.synapse.continuation.ReliantContinuationState 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 4 with ReliantContinuationState

use of org.apache.synapse.continuation.ReliantContinuationState 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 5 with ReliantContinuationState

use of org.apache.synapse.continuation.ReliantContinuationState in project wso2-synapse by wso2.

the class ThrottleMediator method mediate.

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

Aggregations

ReliantContinuationState (org.apache.synapse.continuation.ReliantContinuationState)5 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)5 Mediator (org.apache.synapse.Mediator)4 SynapseLog (org.apache.synapse.SynapseLog)4 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)4 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)3 ContinuationState (org.apache.synapse.ContinuationState)1 AnonymousListMediator (org.apache.synapse.config.xml.AnonymousListMediator)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)1 ListMediator (org.apache.synapse.mediators.ListMediator)1