SynapseEnvironment synapseEnv = (SynapseEnvironment) synEnv.getValue();
/** Initializing autoscaleIn and autoscaleOut Mediators.**/
LoadBalancerConfiguration lbConfig = AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig();
// check whether autoscaling is enabled
if (lbConfig.getLoadBalancerConfig().isAutoscaleEnabled()) {
// get the main sequence mediator
SequenceMediator mainSequence =
(SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence("main");
// iterate through its child mediators
for (Mediator child : mainSequence.getList()) {
// find the InMediator
if (child instanceof InMediator) {
InMediator inSequence = (InMediator) child;
// if the first child of InMediator isn't an AutoscaleInMediator
if (!(inSequence.getList().get(0) instanceof AutoscaleInMediator)) {
// we gonna add it!
inSequence.getList().add(0, new AutoscaleInMediator());
if (log.isDebugEnabled()) {
log.debug("Added Mediator: " + inSequence.getChild(0) + "" +
" to InMediator. Number of child mediators in InMediator" + " is " +
inSequence.getList().size() + ".");
}
}
}
// find the OutMediator
if (child instanceof OutMediator) {
OutMediator outSequence = (OutMediator) child;
// if the first child of OutMediator isn't an AutoscaleOutMediator
if (!(outSequence.getList().get(0) instanceof AutoscaleOutMediator)) {
// we gonna add it!
outSequence.getList().add(0, new AutoscaleOutMediator());
if (log.isDebugEnabled()) {
log.debug("Added Mediator: " + outSequence.getChild(0) + "" +
" to OutMediator. Number of child mediators in OutMediator" +
" is " + outSequence.getList().size() + ".");
}
}
}
}
/** Initializing Autoscaler Task **/
BundleContext bundleContext = context.getBundleContext();
if (log.isDebugEnabled()) {
log.debug("Initiating Autoscaler task service component");
}
if (bundleContext.getServiceReference(TaskManagementService.class.getName()) != null) {
bundleContext.registerService(TaskManagementService.class.getName(),
new AutoscalerTaskMgmtAdminService(), null);
}
AutoscalerTaskInitializer listener = new AutoscalerTaskInitializer();
if (bundleContext.getServiceReference(Axis2ConfigurationContextObserver.class.getName()) != null) {
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) {