Search in sources :

Example 1 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class StartUpController method init.

public void init(SynapseEnvironment synapseEnvironment) {
    this.synapseEnvironment = synapseEnvironment;
    if (taskDescription == null) {
        handleException("Error while initializing the startup. TaskDescription is null.");
    }
    initSynapseTaskManager(synapseEnvironment);
    TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository();
    if (repository == null) {
        handleException("Task Description Repository cannot be found");
        return;
    }
    repository.addTaskDescription(taskDescription);
    if (!processPinnedServers(taskDescription, synapseEnvironment)) {
        return;
    }
    resolveTaskImpl(taskDescription, synapseEnvironment);
    loadTaskProperties();
    initializeTask(synapseEnvironment);
    if (taskDescription.getResource(TaskDescription.INSTANCE) == null || taskDescription.getResource(TaskDescription.CLASSNAME) == null) {
        taskDescription.addResource(TaskDescription.INSTANCE, task);
        taskDescription.addResource(TaskDescription.CLASSNAME, task.getClass().getName());
    }
    try {
        Map<String, Object> map = new HashMap<>();
        map.put(TaskConstants.SYNAPSE_ENV, synapseEnvironment);
        TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
        TaskManager taskManager = synapseTaskManager.getTaskManagerImpl();
        if (taskManager == null) {
            logger.error("Could not initialize Start up controller. TaskManager not found.");
            return;
        }
        taskManager.setProperties(map);
        taskScheduler.init(synapseEnvironment.getSynapseConfiguration().getProperties(), taskManager);
        submitTask(taskScheduler, taskDescription);
        logger.debug("Submitted task [" + taskDescription.getName() + "] to Synapse task scheduler.");
    } catch (Exception e) {
        String msg = "Error starting up Scheduler : " + e.getLocalizedMessage();
        logger.fatal(msg, e);
        throw new SynapseException(msg, e);
    }
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) SynapseTaskManager(org.apache.synapse.task.SynapseTaskManager) SynapseException(org.apache.synapse.SynapseException) TaskDescriptionRepository(org.apache.synapse.task.TaskDescriptionRepository) HashMap(java.util.HashMap) TaskScheduler(org.apache.synapse.task.TaskScheduler) SynapseException(org.apache.synapse.SynapseException) UnknownHostException(java.net.UnknownHostException)

Example 2 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskSchedulerTest method testGetRunningTaskCount.

@Test()
public void testGetRunningTaskCount() {
    TaskManager quartzTaskManager = Mockito.mock(TaskManager.class);
    Mockito.when(quartzTaskManager.getRunningTaskCount()).thenReturn(1);
    org.apache.synapse.task.TaskScheduler taskScheduler = new org.apache.synapse.task.TaskScheduler("CheckPrice");
    taskScheduler.init(new Properties(), quartzTaskManager);
    Assert.assertEquals("Running task count is not the expected value.", 1, taskScheduler.getRunningTaskCount());
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskManagerFactoryTest method testCreateTaskManager.

/**
 * test createTaskManager
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateTaskManager() throws XMLStreamException {
    String inputXML = "<taskManager provider=\"org.apache.synapse.startup.quartz.QuartzTaskManager\"/>";
    OMElement element = AXIOMUtil.stringToOM(inputXML);
    TaskManager taskManager = TaskManagerFactory.createTaskManager(element, null);
    Assert.assertTrue("TaskManager is not created.", taskManager instanceof QuartzTaskManager);
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) TaskManager(org.apache.synapse.task.TaskManager) QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 4 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class TaskManagerFactory method createTaskManager.

public static TaskManager createTaskManager(OMElement elem, Properties properties) {
    OMAttribute prov = elem.getAttribute(PROVIDER_Q);
    if (prov != null) {
        try {
            Class provider = Class.forName(prov.getAttributeValue());
            TaskManager taskManager = (TaskManager) provider.newInstance();
            taskManager.init(getProperties(elem, properties));
            taskManager.setConfigurationProperties(getProperties(elem, properties));
            return taskManager;
        } catch (ClassNotFoundException e) {
            handleException("Cannot locate task provider class : " + prov.getAttributeValue(), e);
        } catch (IllegalAccessException e) {
            handleException("Error instantiating task provider : " + prov.getAttributeValue(), e);
        } catch (InstantiationException e) {
            handleException("Error instantiating task provider : " + prov.getAttributeValue(), e);
        }
    } else {
        handleException("The task 'provider' " + "attribute is required for a taskManager definition");
    }
    return null;
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 5 with TaskManager

use of org.apache.synapse.task.TaskManager in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method defineTaskManager.

public static TaskManager defineTaskManager(SynapseConfiguration config, OMElement elem, Properties properties) {
    if (config.getTaskManager() != null) {
        handleException("Only one remote taskManager can be defined within a configuration");
    }
    TaskManager taskManager = TaskManagerFactory.createTaskManager(elem, properties);
    config.setTaskManager(taskManager);
    return taskManager;
}
Also used : TaskManager(org.apache.synapse.task.TaskManager)

Aggregations

TaskManager (org.apache.synapse.task.TaskManager)9 Test (org.junit.Test)6 Properties (java.util.Properties)4 OMElement (org.apache.axiom.om.OMElement)4 QuartzTaskManager (org.apache.synapse.startup.quartz.QuartzTaskManager)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElementImpl (org.apache.axiom.om.impl.llom.OMElementImpl)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseTaskManager (org.apache.synapse.task.SynapseTaskManager)1 TaskDescription (org.apache.synapse.task.TaskDescription)1 TaskDescriptionRepository (org.apache.synapse.task.TaskDescriptionRepository)1 TaskScheduler (org.apache.synapse.task.TaskScheduler)1