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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations