Search in sources :

Example 11 with PriorityExecutor

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

the class MultiXMLConfigurationSerializer method serializeSynapseXML.

/**
 * Serialize only the elements defined in the top level synapse.xml file back to the
 * synapse.xml file. This method ignores the elements defined in files other than the
 * synapse.xml. Can be used in situations where only the synapse.xml file should be
 * updated at runtime.
 *
 * @param synapseConfig Current Synapse configuration
 * @throws Exception on file I/O error
 */
public void serializeSynapseXML(SynapseConfiguration synapseConfig) throws Exception {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement definitions = fac.createOMElement("definitions", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
    if (synapseConfig.getRegistry() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_REGISTRY_DEFINITION))) {
        RegistrySerializer.serializeRegistry(definitions, synapseConfig.getRegistry());
    }
    if (synapseConfig.getTaskManager() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_TASK_MANAGER_DEFINITION))) {
        TaskManagerSerializer.serializetaskManager(definitions, synapseConfig.getTaskManager());
    }
    Collection<ProxyService> proxyServices = synapseConfig.getProxyServices();
    Collection<SynapseEventSource> eventSources = synapseConfig.getEventSources();
    Collection<Startup> tasks = synapseConfig.getStartups();
    Collection localEntries = synapseConfig.getLocalRegistry().values();
    Collection<PriorityExecutor> executors = synapseConfig.getPriorityExecutors().values();
    Collection<MessageStore> messageStores = synapseConfig.getMessageStores().values();
    Collection<MessageProcessor> messageProcessors = synapseConfig.getMessageProcessors().values();
    Collection<API> apiCollection = synapseConfig.getAPIs();
    Collection<SynapseImport> synapseImportsCollection = synapseConfig.getSynapseImports().values();
    Collection<InboundEndpoint> inboundEndpoints = synapseConfig.getInboundEndpoints();
    Collection<String> comments = synapseConfig.getCommentedTextList();
    for (ProxyService service : proxyServices) {
        if (service.getFileName() == null) {
            ProxyServiceSerializer.serializeProxy(definitions, service);
        }
    }
    for (SynapseEventSource source : eventSources) {
        if (source.getFileName() == null) {
            EventSourceSerializer.serializeEventSource(definitions, source);
        }
    }
    for (Startup task : tasks) {
        if (task instanceof AbstractStartup && task.getFileName() == null) {
            StartupFinder.getInstance().serializeStartup(definitions, task);
        }
    }
    for (Object o : localEntries) {
        if (o instanceof TemplateMediator) {
            TemplateMediator template = (TemplateMediator) o;
            if (template.getFileName() == null) {
                MediatorSerializerFinder.getInstance().getSerializer(template).serializeMediator(definitions, template);
            }
        } else if (o instanceof SequenceMediator) {
            SequenceMediator seq = (SequenceMediator) o;
            if (seq.getFileName() == null) {
                MediatorSerializerFinder.getInstance().getSerializer(seq).serializeMediator(definitions, seq);
            }
        } else if (o instanceof Template) {
            Template templEndpoint = (Template) o;
            if (templEndpoint.getFileName() == null) {
                new TemplateSerializer().serializeEndpointTemplate(templEndpoint, definitions);
            }
        } else if (o instanceof AbstractEndpoint) {
            AbstractEndpoint endpoint = (AbstractEndpoint) o;
            if (endpoint.getFileName() == null) {
                OMElement endpointElem = EndpointSerializer.getElementFromEndpoint(endpoint);
                definitions.addChild(endpointElem);
            }
        } else if (o instanceof Entry) {
            Entry entry = (Entry) o;
            if (entry.getFileName() == null) {
                if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
                    continue;
                }
                EntrySerializer.serializeEntry(entry, definitions);
            }
        }
    }
    for (PriorityExecutor executor : executors) {
        PriorityExecutorSerializer.serialize(definitions, executor, SynapseConstants.SYNAPSE_NAMESPACE);
    }
    for (MessageStore messageStore : messageStores) {
        if (messageStore.getFileName() == null) {
            MessageStoreSerializer.serializeMessageStore(definitions, messageStore);
        }
    }
    for (MessageProcessor messageProcessor : messageProcessors) {
        if (messageProcessor.getFileName() == null) {
            MessageProcessorSerializer.serializeMessageProcessor(definitions, messageProcessor);
        }
    }
    for (API api : apiCollection) {
        if (api.getFileName() == null) {
            APISerializer.serializeAPI(definitions, api);
        }
    }
    for (SynapseImport synapseImport : synapseImportsCollection) {
        if (synapseImport.getFileName() == null) {
            SynapseImportSerializer.serializeImport(definitions, synapseImport);
        }
    }
    for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
        if (inboundEndpoint.getFileName() == null) {
            InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
        }
    }
    serializeComments(comments, definitions);
    serializeSynapseXML(definitions);
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Template(org.apache.synapse.endpoints.Template) SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Entry(org.apache.synapse.config.Entry) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateSerializer(org.apache.synapse.config.xml.endpoints.TemplateSerializer) AbstractStartup(org.apache.synapse.startup.AbstractStartup) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) OMFactory(org.apache.axiom.om.OMFactory) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) Collection(java.util.Collection) API(org.apache.synapse.rest.API) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Startup(org.apache.synapse.Startup) AbstractStartup(org.apache.synapse.startup.AbstractStartup)

Example 12 with PriorityExecutor

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

the class ListenerContextBuilder method createPriorityExecutor.

private PriorityExecutor createPriorityExecutor(final OMElement definitions) throws AxisFault {
    assert definitions != null;
    OMElement executorElem = definitions.getFirstChildWithName(new QName(ExecutorConstants.PRIORITY_EXECUTOR));
    if (executorElem == null) {
        handleException(ExecutorConstants.PRIORITY_EXECUTOR + " configuration is mandatory for priority based routing");
    }
    PriorityExecutor executor = PriorityExecutorFactory.createExecutor(null, executorElem, false, new Properties());
    executor.init();
    return executor;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Properties(java.util.Properties)

Example 13 with PriorityExecutor

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

the class PriorityExecutorFactoryTest method testCreateExecutorWithFixedSizeQueues.

/**
 * Test creating PriorityExecutor by defining fixed sized queues in the xml configuration
 * @throws XMLStreamException
 * @throws AxisFault
 */
public void testCreateExecutorWithFixedSizeQueues() throws XMLStreamException, AxisFault {
    OMElement element = AXIOMUtil.stringToOM("<priority-executor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor2\">\n" + "   <queues isFixedSize=\"true\">\n" + "      <queue size=\"25\" priority=\"10\"/>\n" + "      <queue size=\"15\" 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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Properties(java.util.Properties)

Example 14 with PriorityExecutor

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

the class PriorityExecutorFactoryTest method testCreateExecutorWithNextAlgorithm.

/**
 * Test creating PriorityExecutor with NextQueueAlgorithm
 * @throws XMLStreamException
 * @throws AxisFault
 */
public void testCreateExecutorWithNextAlgorithm() throws XMLStreamException, AxisFault {
    OMElement element = AXIOMUtil.stringToOM("<priority-executor xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "   <queues nextQueue=\"org.apache.synapse.commons.executors.PRRNextQueueAlgorithm\">\n" + "      <queue size=\"25\" priority=\"10\"/>\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, false, new Properties());
    assertNotNull("Next queue algorithm should not be null", executor.getQueue().getNextQueueAlgorithm());
}
Also used : OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Properties(java.util.Properties)

Example 15 with PriorityExecutor

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

the class SynapseXMLConfigurationFactory method defineExecutor.

public static PriorityExecutor defineExecutor(SynapseConfiguration config, OMElement elem, Properties properties) {
    PriorityExecutor executor = null;
    try {
        executor = PriorityExecutorFactory.createExecutor(XMLConfigConstants.SYNAPSE_NAMESPACE, elem, true, properties);
        assert executor != null;
        config.addPriorityExecutor(executor.getName(), executor);
    } catch (AxisFault axisFault) {
        String msg = "Executor configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EXECUTORS, msg, axisFault);
    }
    return executor;
}
Also used : AxisFault(org.apache.axis2.AxisFault) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor)

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