Search in sources :

Example 6 with PriorityExecutor

use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.

the class PriorityExecutorSerializerTest method testSerializeWithUnboundedQueues.

/**
 * Test serializing a PriorityExecutor created with UnboundedQueues
 */
public void testSerializeWithUnboundedQueues() {
    PriorityExecutor priorityExecutor = new PriorityExecutor();
    priorityExecutor.setName("executor1");
    List<InternalQueue> internalQueueList = new ArrayList<>();
    internalQueueList.add(new UnboundedQueue(10));
    internalQueueList.add(new UnboundedQueue(5));
    MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, false, new PRRNextQueueAlgorithm());
    priorityExecutor.setQueue(multiPriorityBlockingQueue);
    OMElement element = PriorityExecutorSerializer.serialize(null, priorityExecutor, "http://ws.apache.org/ns/synapse");
    assertEquals("Invalid serialization of PriorityExecutor", "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues isFixedSize=\"false\"><queue priority=\"10\" /><queue priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>", element.toString());
}
Also used : PRRNextQueueAlgorithm(org.apache.synapse.commons.executors.PRRNextQueueAlgorithm) UnboundedQueue(org.apache.synapse.commons.executors.queues.UnboundedQueue) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) MultiPriorityBlockingQueue(org.apache.synapse.commons.executors.MultiPriorityBlockingQueue) InternalQueue(org.apache.synapse.commons.executors.InternalQueue)

Example 7 with PriorityExecutor

use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.

the class PriorityExecutorSerializerTest method testSerialize.

/**
 * Test serializing a PriorityExecutor created with FixedSizeQueues
 */
public void testSerialize() {
    PriorityExecutor priorityExecutor = new PriorityExecutor();
    priorityExecutor.setName("executor1");
    List<InternalQueue> internalQueueList = new ArrayList<>();
    internalQueueList.add(new FixedSizeQueue(10, 10));
    internalQueueList.add(new FixedSizeQueue(5, 25));
    MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, true, new PRRNextQueueAlgorithm());
    priorityExecutor.setQueue(multiPriorityBlockingQueue);
    OMElement element = PriorityExecutorSerializer.serialize(null, priorityExecutor, "http://ws.apache.org/ns/synapse");
    assertEquals("Invalid serialization of PriorityExecutor", "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues><queue size=\"10\" priority=\"10\" /><queue size=\"25\" priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>", element.toString());
}
Also used : FixedSizeQueue(org.apache.synapse.commons.executors.queues.FixedSizeQueue) PRRNextQueueAlgorithm(org.apache.synapse.commons.executors.PRRNextQueueAlgorithm) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) MultiPriorityBlockingQueue(org.apache.synapse.commons.executors.MultiPriorityBlockingQueue) InternalQueue(org.apache.synapse.commons.executors.InternalQueue)

Example 8 with PriorityExecutor

use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.

the class PriorityExecutorSerializerTest method testSerializeGivenParentElement.

/**
 * Test serializing a PriorityExecutor when parent element is defined
 * @throws XMLStreamException
 */
public void testSerializeGivenParentElement() throws XMLStreamException {
    OMElement parentElement = AXIOMUtil.stringToOM("<definitions></definitions>");
    PriorityExecutor priorityExecutor = new PriorityExecutor();
    priorityExecutor.setName("executor1");
    List<InternalQueue> internalQueueList = new ArrayList<>();
    internalQueueList.add(new FixedSizeQueue(10, 10));
    internalQueueList.add(new FixedSizeQueue(5, 25));
    MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, true, new PRRNextQueueAlgorithm());
    priorityExecutor.setQueue(multiPriorityBlockingQueue);
    PriorityExecutorSerializer.serialize(parentElement, priorityExecutor, "http://ws.apache.org/ns/synapse");
    assertEquals("Invalid serialization of PriorityExecutor", "<definitions>" + "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues><queue size=\"10\" priority=\"10\" /><queue size=\"25\" priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>" + "</definitions>", parentElement.toString());
}
Also used : FixedSizeQueue(org.apache.synapse.commons.executors.queues.FixedSizeQueue) PRRNextQueueAlgorithm(org.apache.synapse.commons.executors.PRRNextQueueAlgorithm) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) MultiPriorityBlockingQueue(org.apache.synapse.commons.executors.MultiPriorityBlockingQueue) InternalQueue(org.apache.synapse.commons.executors.InternalQueue)

Example 9 with PriorityExecutor

use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.

the class SynapseObserverTest method testSimpleObserver.

public void testSimpleObserver() {
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.setAxisConfiguration(new AxisConfiguration());
    synapseConfig.registerObserver(observer);
    Endpoint epr = new AddressEndpoint();
    epr.setName("endpoint1");
    synapseConfig.addEndpoint(epr.getName(), epr);
    assertItemAdded(epr.getName(), ENDPOINT);
    synapseConfig.removeEndpoint(epr.getName());
    assertItemRemoved(epr.getName(), ENDPOINT);
    SequenceMediator seq = new SequenceMediator();
    seq.setName("sequence1");
    synapseConfig.addSequence(seq.getName(), seq);
    assertItemAdded(seq.getName(), SEQUENCE);
    synapseConfig.removeSequence(seq.getName());
    assertItemRemoved(seq.getName(), SEQUENCE);
    TemplateMediator template = new TemplateMediator();
    template.setName("template1");
    synapseConfig.addSequenceTemplate(template.getName(), template);
    assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
    synapseConfig.removeSequenceTemplate(template.getName());
    assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
    Entry entry = new Entry();
    entry.setKey("entry1");
    synapseConfig.addEntry(entry.getKey(), entry);
    assertItemAdded(entry.getKey(), ENTRY);
    synapseConfig.removeEntry(entry.getKey());
    assertItemRemoved(entry.getKey(), ENTRY);
    ProxyService proxy = new ProxyService("proxy1");
    synapseConfig.addProxyService(proxy.getName(), proxy);
    assertItemAdded(proxy.getName(), PROXY);
    synapseConfig.removeProxyService(proxy.getName());
    assertItemRemoved(proxy.getName(), PROXY);
    Startup startup = new StartUpController();
    startup.setName("startup1");
    synapseConfig.addStartup(startup);
    assertItemAdded(startup.getName(), STARTUP);
    synapseConfig.removeStartup(startup.getName());
    assertItemRemoved(startup.getName(), STARTUP);
    SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
    synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
    assertItemAdded(eventSrc.getName(), EVENT_SRC);
    synapseConfig.removeEventSource(eventSrc.getName());
    assertItemRemoved(eventSrc.getName(), EVENT_SRC);
    PriorityExecutor exec = new PriorityExecutor();
    exec.setName("exec1");
    synapseConfig.addPriorityExecutor(exec.getName(), exec);
    assertItemAdded(exec.getName(), EXECUTOR);
    synapseConfig.removeExecutor(exec.getName());
    assertItemRemoved(exec.getName(), EXECUTOR);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StartUpController(org.apache.synapse.startup.quartz.StartUpController) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Startup(org.apache.synapse.Startup)

Example 10 with PriorityExecutor

use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.

the class MultiXMLConfigurationBuilder method createExecutors.

private static void createExecutors(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
    File executorsDir = new File(rootDirPath, EXECUTORS_DIR);
    if (executorsDir.exists()) {
        if (log.isDebugEnabled()) {
            log.debug("Loading event sources from : " + executorsDir.getPath());
        }
        Iterator executors = FileUtils.iterateFiles(executorsDir, extensions, false);
        while (executors.hasNext()) {
            File file = (File) executors.next();
            try {
                OMElement document = getOMElement(file);
                PriorityExecutor executor = SynapseXMLConfigurationFactory.defineExecutor(synapseConfig, document, properties);
                if (executor != null) {
                    executor.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), executor.getName());
                }
            } catch (Exception e) {
                String msg = "Executor configuration cannot be built from : " + file.getName();
                handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EXECUTORS, msg, e);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Aggregations

PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)19 OMElement (org.apache.axiom.om.OMElement)11 Properties (java.util.Properties)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)4 ArrayList (java.util.ArrayList)3 InternalQueue (org.apache.synapse.commons.executors.InternalQueue)3 MultiPriorityBlockingQueue (org.apache.synapse.commons.executors.MultiPriorityBlockingQueue)3 PRRNextQueueAlgorithm (org.apache.synapse.commons.executors.PRRNextQueueAlgorithm)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 File (java.io.File)2 AxisFault (org.apache.axis2.AxisFault)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Startup (org.apache.synapse.Startup)2