use of org.apache.synapse.task.TaskDescription in project wso2-synapse by wso2.
the class ScheduledMessageProcessor method start.
@Override
public boolean start() {
for (int i = 0; i < memberCount; i++) {
/*
* Make sure to fetch the task after initializing the message sender
* and consumer properly. Otherwise you may get NullPointer
* exceptions.
*/
task = this.getTask();
TaskDescription taskDescription = new TaskDescription();
taskDescription.setName(TASK_PREFIX + name + i);
taskDescription.setTaskGroup(MessageProcessorConstants.SCHEDULED_MESSAGE_PROCESSOR_GROUP);
/*
* If this interval value is less than 1000 ms, ntask will throw an
* exception while building the task. So to get around that we are
* setting threshold interval value of 1000 ms to the task
* description here. But actual interval value may be less than 1000
* ms, and hence isThrotling is set to TRUE.
*/
if (interval < MessageProcessorConstants.THRESHOULD_INTERVAL) {
taskDescription.setInterval(MessageProcessorConstants.THRESHOULD_INTERVAL);
} else {
taskDescription.setInterval(interval);
}
taskDescription.setIntervalInMs(true);
taskDescription.addResource(TaskDescription.INSTANCE, task);
taskDescription.addResource(TaskDescription.CLASSNAME, task.getClass().getName());
/*
* If there is a Cron Expression we need to set it into the
* TaskDescription so that the framework will take care of it.
*/
if (cronExpression != null) {
taskDescription.setCronExpression(cronExpression);
}
taskManager.schedule(taskDescription);
}
logger.info("Started message processor. [" + getName() + "].");
/*
* If the Message Processor is Deactivated through the Advanced parameter
* explicitly, then we deactivate the task immediately.
*/
if (isProcessorStartAsDeactivated()) {
deactivate();
}
return true;
}
use of org.apache.synapse.task.TaskDescription in project wso2-synapse by wso2.
the class SimpleQuartzSerializer method serializeStartup.
public OMElement serializeStartup(OMElement parent, Startup s) {
if (!(s instanceof StartUpController)) {
throw new SynapseException("called TaskSerializer on some other " + "kind of startup" + s.getClass().getName());
}
StartUpController sq = (StartUpController) s;
TaskDescription taskDescription = sq.getTaskDescription();
if (taskDescription != null) {
OMElement task = TaskDescriptionSerializer.serializeTaskDescription(SynapseConstants.SYNAPSE_OMNAMESPACE, taskDescription);
if (task == null) {
throw new SynapseException("Task Element can not be null.");
}
if (parent != null) {
parent.addChild(task);
}
return task;
} else {
throw new SynapseException("Task Description is null");
}
}
use of org.apache.synapse.task.TaskDescription in project wso2-synapse by wso2.
the class SimpleQuartzFactory method createStartup.
public Startup createStartup(OMElement el) {
if (log.isDebugEnabled()) {
log.debug("Creating StartUpController Task");
}
if (el.getQName().equals(TASK)) {
StartUpController startUpController = new StartUpController();
TaskDescription taskDescription = TaskDescriptionFactory.createTaskDescription(el, XMLConfigConstants.SYNAPSE_OMNAMESPACE);
if (taskDescription == null) {
handleException("Invalid task - Task description can not be created from :" + el);
return null;
}
startUpController.setName(taskDescription.getName());
startUpController.setTaskDescription(taskDescription);
startUpController.setDescription(taskDescription.getTaskDescription());
return startUpController;
} else {
handleException("Syntax error in the task : wrong QName for the task");
return null;
}
}
use of org.apache.synapse.task.TaskDescription in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration8.
/**
* Test serializeConfigurationMethod with startUp added for SynapseConfiguration and assert OMElement returned
*/
@Test
public void testSerializeConfiguration8() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
StartUpController startup = new StartUpController();
startup.setName("testStartup");
TaskDescription taskDescription = new TaskDescription();
taskDescription.setName("testTask");
startup.setTaskDescription(taskDescription);
synapseConfiguration.addStartup(startup);
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("StartUp added is not serialized.", element.getChildren().next().toString().contains("name=\"testTask\""));
}
use of org.apache.synapse.task.TaskDescription in project wso2-synapse by wso2.
the class TaskSchedulerTest method testScheduleTask.
@Test()
public void testScheduleTask() throws Exception {
String path = this.getClass().getClassLoader().getResource("task/task_TestScheduler.xml").getFile();
OMElement taskOme = loadOMElement(path);
TaskDescription taskDescription = TaskDescriptionFactory.createTaskDescription(taskOme, SYNAPSE_OMNAMESPACE);
TaskManager quartzTaskManager = Mockito.mock(TaskManager.class);
Mockito.when(quartzTaskManager.schedule(taskDescription)).thenReturn(true);
org.apache.synapse.task.TaskScheduler taskScheduler = new org.apache.synapse.task.TaskScheduler("task");
Assert.assertFalse("Task cannot be scheduled before initialization.", taskScheduler.scheduleTask(taskDescription));
taskScheduler.init(new Properties(), quartzTaskManager);
Assert.assertTrue("Task at file task_TestScheduler.xml not " + "scheduled even after initializing the scheduler.", taskScheduler.scheduleTask(taskDescription));
}
Aggregations