/*
* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.dataservices.taskscheduler.multitenancy;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.synapse.task.TaskDescriptionRepository;
import org.apache.synapse.task.TaskScheduler;
import org.wso2.carbon.dataservices.taskscheduler.constants.TaskSchedulerConstants;
import org.wso2.carbon.task.TaskManager;
import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
/**
* TaskSchedulerInitializer class handles the multi-tenancy requirements basically initializing
* all the entities that are required to carry out the task execution in a self-contained manner.
*/
public class TaskSchedulerInitializer extends AbstractAxis2ConfigurationContextObserver {
/**
* This method initializes the entities Task Manager, Task Scheduler and the TaskDescription
* Repository and sets as properties of the associated ConfigurationContext per each tenant.
*
* @param configurationContext ConfigurationContext
*/
public void createdConfigurationContext(ConfigurationContext configurationContext) {
/**
* Initializing the Task Manager
*/
TaskManager taskManager = (TaskManager) configurationContext.getProperty(
TaskManager.CARBON_TASK_MANAGER);
if (taskManager == null) {
taskManager = new TaskManager();
configurationContext.setProperty(TaskManager.CARBON_TASK_MANAGER, taskManager);
}
/**
* Initializing the Task Scheduler
*/
TaskScheduler taskScheduler = (TaskScheduler) configurationContext.getProperty(
TaskSchedulerConstants.CARBON_TASK_SCHEDULER);
if (taskScheduler == null) {
taskScheduler = new TaskScheduler(TaskManager.CARBON_TASK_SCHEDULER);
taskScheduler.init(null);
configurationContext.setProperty(
TaskSchedulerConstants.CARBON_TASK_SCHEDULER, taskScheduler);
} else if (taskScheduler.isInitialized()) {
taskScheduler.init(null);
}
/**
* Initializing the Task Description Repository
*/
TaskDescriptionRepository taskDescriptionRepository =
(TaskDescriptionRepository) configurationContext.getProperty(
TaskSchedulerConstants.CARBON_TASK_REPOSITORY);
if (taskDescriptionRepository == null) {
taskDescriptionRepository = new TaskDescriptionRepository();
configurationContext.setProperty(
TaskSchedulerConstants.CARBON_TASK_REPOSITORY, taskDescriptionRepository);
}
}
}