use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class EnqueueMediator method mediate.
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog log = getLog(synCtx);
if (log.isTraceOrDebugEnabled()) {
log.traceOrDebug("Start: enqueue mediator");
}
assert executorName != null : "executor name shouldn't be null";
PriorityExecutor executor = synCtx.getConfiguration().getPriorityExecutors().get(executorName);
if (executor == null) {
log.auditWarn("Cannot find executor " + executorName + ". Using existing thread for mediation");
Mediator m = synCtx.getSequence(sequenceName);
if (m != null && m instanceof SequenceMediator) {
return m.mediate(synCtx);
} else {
handleException("Sequence cannot be found : " + sequenceName, synCtx);
return false;
}
}
Mediator m = synCtx.getSequence(sequenceName);
if (m != null && m instanceof SequenceMediator) {
MediatorWorker worker = new MediatorWorker(m, synCtx);
try {
// execute with the given priority
executor.execute(worker, priority);
} catch (RejectedExecutionException ex) {
// if RejectedExecutionException, jump to fault handler
handleException("Unable to process message in priority executor " + executorName + " with priority " + priority + ". Thread pool exhausted.", synCtx);
}
// with the nio transport, this causes the listener not to write a 202
// Accepted response, as this implies that Synapse does not yet know if
// a 202 or 200 response would be written back.
((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
if (log.isTraceOrDebugEnabled()) {
log.traceOrDebug("End: enqueue mediator");
}
return true;
} else {
handleException("Sequence cannot be found : " + sequenceName, synCtx);
return false;
}
}
use of org.apache.synapse.Mediator 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;
}
use of org.apache.synapse.Mediator 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;
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class FailoverForwardingService method sendThroughFaultSeq.
/**
* Sending the out message through the fault sequence.
*
* @param msgCtx Synapse {@link MessageContext} to be sent through the fault
* sequence.
*/
public void sendThroughFaultSeq(MessageContext msgCtx) {
if (faultSeq == null) {
log.warn("Failed to send the message through the fault sequence. Sequence name does not Exist.");
return;
}
Mediator mediator = msgCtx.getSequence(faultSeq);
if (mediator == null) {
log.warn("Failed to send the message through the fault sequence. Sequence [" + faultSeq + "] does not Exist.");
return;
}
mediator.mediate(msgCtx);
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class FailoverForwardingService method sendThroughDeactivateSeq.
/**
* Sending the out message through the deactivate sequence.
*
* @param msgCtx Synapse {@link MessageContext} to be sent through the deactivate
* sequence.
*/
public void sendThroughDeactivateSeq(MessageContext msgCtx) {
if (deactivateSeq == null) {
log.warn("Failed to send the message through the deactivate sequence. Sequence name does not Exist.");
return;
}
Mediator mediator = msgCtx.getSequence(deactivateSeq);
if (mediator == null) {
log.warn("Failed to send the message through the deactivate sequence. Sequence [" + deactivateSeq + "] does not Exist.");
return;
}
mediator.mediate(msgCtx);
}
Aggregations