Search in sources :

Example 1 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());
    }
    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) {
        // pop the Error handler belonging to current mediator
        Stack faultStack = synCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            Object o = faultStack.peek();
            if (errorHandler != null) {
                Mediator errorHandlerMediator = synCtx.getSequence(errorHandler);
                if (o instanceof MediatorFaultHandler && errorHandlerMediator.equals(((MediatorFaultHandler) o).getFaultMediator())) {
                    faultStack.pop();
                }
            }
        }
        // if flow completed, remove top ContinuationState from stack
        ContinuationStackManager.popContinuationStateStack(synCtx);
    }
    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 2 with FlowContinuableMediator

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

the class ValidateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Validate mediator : Mediating from ContinuationState");
    }
    boolean result;
    if (!continuationState.hasChild()) {
        result = super.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (RuntimeStatisticCollector.isStatisticsEnabled()) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : 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)

Example 3 with FlowContinuableMediator

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

the class InMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("In mediator : Mediating from ContinuationState");
    }
    boolean result;
    if (!continuationState.hasChild()) {
        result = super.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (RuntimeStatisticCollector.isStatisticsEnabled()) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : 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)

Example 4 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 5 with FlowContinuableMediator

use of org.apache.synapse.mediators.FlowContinuableMediator 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)

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