use of org.apache.synapse.commons.executors.PriorityExecutor 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.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorDeployer method updateSynapseArtifact.
@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
if (log.isDebugEnabled()) {
log.debug("PriorityExecutor update from file : " + fileName + " has started");
}
try {
PriorityExecutor e = PriorityExecutorFactory.createExecutor(SynapseConstants.SYNAPSE_NAMESPACE, artifactConfig, true, properties);
if (e == null) {
handleSynapseArtifactDeploymentError("PriorityExecutor update failed. The artifact " + "defined in the file: " + fileName + " is not a valid executor.");
return null;
}
e.setFileName(new File(fileName).getName());
if (log.isDebugEnabled()) {
log.debug("Executor: " + e.getName() + " has been built from the file: " + fileName);
}
e.init();
PriorityExecutor existingExecutor = getSynapseConfiguration().getPriorityExecutors().get(existingArtifactName);
if (existingArtifactName.equals(e.getName())) {
getSynapseConfiguration().updatePriorityExecutor(existingArtifactName, e);
} else {
// The user has changed the name of the executor
// We should add the updated executor as a new executor and remove the old one
getSynapseConfiguration().addPriorityExecutor(e.getName(), e);
getSynapseConfiguration().removeExecutor(existingArtifactName);
log.info("Executor: " + existingArtifactName + " has been undeployed");
}
waitForCompletion();
existingExecutor.destroy();
log.info("PriorityExecutor: " + e.getName() + " has been updated from the file: " + fileName);
return e.getName();
} catch (DeploymentException e) {
handleSynapseArtifactDeploymentError("Error while updating the executor from the " + "file: " + fileName);
} catch (AxisFault e) {
handleSynapseArtifactDeploymentError("Error while creating the executor from the " + "configuration in file: " + fileName);
}
return null;
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorDeployer method restoreSynapseArtifact.
@Override
public void restoreSynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Restoring PriorityExecutor with name : " + artifactName + " : Started");
}
try {
PriorityExecutor e = getSynapseConfiguration().getPriorityExecutors().get(artifactName);
OMElement entryElem = PriorityExecutorSerializer.serialize(null, e, SynapseConstants.SYNAPSE_NAMESPACE);
if (e.getFileName() != null) {
String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.EXECUTORS_DIR + File.separator + e.getFileName();
writeToFile(entryElem, fileName);
if (log.isDebugEnabled()) {
log.debug("Restoring the PriorityExecutor with name : " + artifactName + " : Completed");
}
log.info("PriorityExecutor named '" + artifactName + "' has been restored");
} else {
handleSynapseArtifactDeploymentError("Couldn't restore the PriorityExecutor named '" + artifactName + "', filename cannot be found");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Restoring of the PriorityExecutor named '" + artifactName + "' has failed", e);
}
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorFactoryTest method testCreateExecutor.
/**
* Test creating PriorityExecutor from given xml configuration
* @throws XMLStreamException
* @throws AxisFault
*/
public void testCreateExecutor() throws XMLStreamException, AxisFault {
OMElement element = AXIOMUtil.stringToOM("<priority-executor xmlns:ns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<ns:queues></ns:queues>" + "</priority-executor>");
PriorityExecutor executor = PriorityExecutorFactory.createExecutor("http://ws.apache.org/ns/synapse", element, false, new Properties());
assertNotNull("Error creating PriorityExecutor", executor);
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorFactoryTest method testCreateExecutorWithQueues.
/**
* Test creating PriorityExecutor by defining multiple queues in the xml configuration
* @throws XMLStreamException
* @throws AxisFault
*/
public void testCreateExecutorWithQueues() throws XMLStreamException, AxisFault {
OMElement element = AXIOMUtil.stringToOM("<priority-executor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">\n" + " <queues isFixedSize=\"false\">\n" + " <queue priority=\"10\"/>\n" + " <queue priority=\"5\"/>\n" + " </queues>\n" + " <threads max=\"100\" core=\"20\" keep-alive=\"5\"/>\n" + "</priority-executor>");
PriorityExecutor executor = PriorityExecutorFactory.createExecutor("http://ws.apache.org/ns/synapse", element, true, new Properties());
assertEquals("Priority executor queue count invalid", 2, executor.getQueue().getQueues().size());
}
Aggregations