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);
}
}
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());
}
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);
}
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;
}
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;
}
Aggregations