bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(),
listener, null);
}
if (configurationContext != null) {
TaskScheduler scheduler =
(TaskScheduler) configurationContext.getProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER);
if (scheduler == null) {
scheduler = new TaskScheduler(TaskConstants.TASK_SCHEDULER);
scheduler.init(null);
configurationContext.setProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER,
scheduler);
} else if (!scheduler.isInitialized()) {
scheduler.init(null);
}
}
String autoscalerClass = lbConfig.getLoadBalancerConfig().getAutoscalerTaskClass();
Task task;
if (autoscalerClass != null) {
try {
task = (Task) Class.forName(autoscalerClass).newInstance();
} catch (Exception e) {
String msg = "Cannot instantiate Autoscaling Task. Class: " + autoscalerClass
+". It should implement 'org.apache.synapse.task.Task' and "
+"'org.apache.synapse.ManagedLifecycle' interfaces.";
log.error(msg, e);
throw new RuntimeException(msg, e);
}
} else {
task = new ServiceRequestsInFlightAutoscaler();
}
// ServiceRequestsInFlightAutoscaler autoscalerTask =
// new ServiceRequestsInFlightAutoscaler();
((ManagedLifecycle) task).init(synapseEnv);
// specify scheduler task details
JobBuilder jobBuilder = JobBuilder.newJob(AutoscalingJob.class)
.withIdentity("autoscalerJob");
JobDetail job = jobBuilder.build();
Map<String, Object> dataMap = job.getJobDataMap();
dataMap.put(AutoscalingJob.AUTOSCALER_TASK, task);
dataMap.put(AutoscalingJob.SYNAPSE_ENVI, synapseEnv);
final TaskDescription taskDescription = new TaskDescription();
taskDescription.setTaskClass(ServiceRequestsInFlightAutoscaler.class.getName());
taskDescription.setName("autoscaler");
//taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
int interval = AutoscalerTaskDSHolder.getInstance().getLoadBalancerConfig().getAutoscalerTaskInterval();
taskDescription.setInterval(interval);
taskDescription.setStartTime(new Date(System.currentTimeMillis() + (interval*2)));
TaskSchedulingManager scheduler = new TaskSchedulingManager();
scheduler.scheduleTask(taskDescription, dataMap, configurationContext);
} else {
log.info("Autoscaling is disabled.");