Search in sources :

Example 1 with TaskScheduler

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

the class StartUpController method destroy.

/**
 * Remove the scheduled task completely. So only un-deployment will remove the task. Server node shutdown will keep
 * task intact in the registry.
 * <p>
 * This was introduced as a fix for product-ei#1206.
 *
 * @param removeTask whether keep the task or not.
 */
public void destroy(boolean removeTask) {
    if (!destroyTask()) {
        return;
    }
    // Need to re initialize startup controller to support updates from source view
    if (!synapseTaskManager.isInitialized() && synapseEnvironment != null) {
        init(synapseEnvironment);
    }
    if (synapseTaskManager.isInitialized()) {
        TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
        if (taskScheduler != null && taskScheduler.isInitialized() && removeTask) {
            taskScheduler.deleteTask(taskDescription.getName(), taskDescription.getTaskGroup());
        }
        TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository();
        if (repository != null) {
            repository.removeTaskDescription(taskDescription.getName());
        }
    }
}
Also used : TaskDescriptionRepository(org.apache.synapse.task.TaskDescriptionRepository) TaskScheduler(org.apache.synapse.task.TaskScheduler)

Example 2 with TaskScheduler

use of org.apache.synapse.task.TaskScheduler 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)

Aggregations

TaskDescriptionRepository (org.apache.synapse.task.TaskDescriptionRepository)2 TaskScheduler (org.apache.synapse.task.TaskScheduler)2 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseTaskManager (org.apache.synapse.task.SynapseTaskManager)1 TaskManager (org.apache.synapse.task.TaskManager)1