use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class OutMediator method mediate.
/**
* Executes the list of sub/child mediators, if the filter condition is satisfied
*
* @param synCtx the current message
* @return true if filter condition fails. else returns as per List mediator semantics
*/
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Out mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
boolean result = true;
if (test(synCtx)) {
synLog.traceOrDebug("Current message is outgoing - executing child mediators");
ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
result = super.mediate(synCtx);
if (result) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
}
} else {
synLog.traceOrDebug("Current message is a request - skipping child mediators");
}
synLog.traceOrDebug("End : Out mediator");
return result;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class OutMediator method mediate.
public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Out 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;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class SwitchMediator method mediate.
/**
* Iterate over switch cases and find match and execute selected sequence
*
* @param synCtx current context
* @return as per standard semantics
*/
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Switch mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
int parentsEffectiveTraceState = synCtx.getTracingState();
// if I have been explicitly asked to enable or disable tracing, set it to the message
// to pass it on; else, do nothing -> i.e. let the parents state flow
setEffectiveTraceState(synCtx);
String sourceText = source.stringValueOf(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("XPath : " + source + " evaluates to : " + sourceText);
}
try {
if ((sourceText == null || cases.isEmpty()) && defaultCase != null) {
synLog.traceOrDebug("Source XPath evaluated to : null or no switch " + "cases found. Executing the default case");
ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
boolean result = defaultCase.mediate(synCtx);
if (result) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
}
return result;
} else {
for (int i = 0; i < cases.size(); i++) {
SwitchCase swCase = cases.get(i);
if (swCase != null) {
if (swCase.matches(sourceText)) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Matching case found : " + swCase.getRegex());
}
ContinuationStackManager.addReliantContinuationState(synCtx, i + 1, getMediatorPosition());
boolean result = swCase.mediate(synCtx);
if (result) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
}
return result;
}
}
}
if (defaultCase != null) {
// if any of the switch cases did not match
synLog.traceOrDebug("None of the switch cases matched - executing default");
ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
boolean result = defaultCase.mediate(synCtx);
if (result) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
}
return result;
} else {
synLog.traceOrDebug("None of the switch cases matched - no default case");
}
}
} finally {
synCtx.setTracingState(parentsEffectiveTraceState);
}
synLog.traceOrDebug("End : Switch mediator");
return true;
}
use of org.apache.synapse.SynapseLog 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;
}
use of org.apache.synapse.SynapseLog 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;
}
Aggregations