Github user johannnallathamby commented on a diff in the pull request: https://github.com/apache/stratos/pull/50#discussion_r22122404 --- Diff: components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerDSComponent.java --- @@ -44,106 +41,114 @@ /** * Registering Cloud Controller Service. - * + * * @scr.component name="org.apache.stratos.cloud.controller" immediate="true" - * @scr.reference name="ntask.component" interface="org.wso2.carbon.ntask.core.service.TaskService" - * cardinality="1..1" policy="dynamic" bind="setTaskService" - * unbind="unsetTaskService" - * @scr.reference name="registry.service" - * interface= - * "org.wso2.carbon.registry.core.service.RegistryService" - * cardinality="1..1" policy="dynamic" bind="setRegistryService" - * unbind="unsetRegistryService" + * @scr.reference name="ntask.component" + * interface="org.wso2.carbon.ntask.core.service.TaskService" + * cardinality="1..1" policy="dynamic" bind="setTaskService" + * unbind="unsetTaskService" + * @scr.reference name="registry.service" interface= + * "org.wso2.carbon.registry.core.service.RegistryService" + * cardinality="1..1" policy="dynamic" bind="setRegistryService" + * unbind="unsetRegistryService" * @scr.reference name="config.context.service" - * interface="org.wso2.carbon.utils.ConfigurationContextService" - * cardinality="1..1" policy="dynamic" - * bind="setConfigurationContextService" - * unbind="unsetConfigurationContextService" + * interface="org.wso2.carbon.utils.ConfigurationContextService" + * cardinality="1..1" policy="dynamic" + * bind="setConfigurationContextService" + * unbind="unsetConfigurationContextService" */ public class CloudControllerDSComponent { - private static final Log log = LogFactory.getLog(CloudControllerDSComponent.class); - - protected void activate(ComponentContext context) { - try { - - // Start instance status event message listener - TopicSubscriber subscriber = new TopicSubscriber(CloudControllerConstants.INSTANCE_TOPIC); - subscriber.setMessageListener(new InstanceStatusEventMessageListener()); - Thread tsubscriber = new Thread(subscriber); - tsubscriber.start(); - - // Start instance status message delegator - InstanceStatusEventMessageDelegator delegator = new InstanceStatusEventMessageDelegator(); - Thread tdelegator = new Thread(delegator); - tdelegator.start(); - - // Register cloud controller service - BundleContext bundleContext = context.getBundleContext(); - bundleContext.registerService(CloudControllerService.class.getName(), new CloudControllerServiceImpl(), null); - - if(log.isInfoEnabled()) { - log.info("Scheduling tasks"); - } - - TopologySynchronizerTaskScheduler - .schedule(ServiceReferenceHolder.getInstance() - .getTaskService()); - - } catch (Throwable e) { - log.error("******* Cloud Controller Service bundle is failed to activate ****", e); - } - } - - protected void setTaskService(TaskService taskService) { - if (log.isDebugEnabled()) { - log.debug("Setting the Task Service"); - } - ServiceReferenceHolder.getInstance().setTaskService(taskService); - } - - protected void unsetTaskService(TaskService taskService) { - if (log.isDebugEnabled()) { - log.debug("Unsetting the Task Service"); - } - ServiceReferenceHolder.getInstance().setTaskService(null); - } - + private static final Log log = LogFactory + .getLog(CloudControllerDSComponent.class); + + protected void activate(ComponentContext context) { + try { + + // Start instance status event message listener + TopicSubscriber subscriber = new TopicSubscriber( + CloudControllerConstants.INSTANCE_TOPIC); + subscriber.setMessageListener( + new InstanceStatusEventMessageListener()); + Thread tsubscriber = new Thread(subscriber); + tsubscriber.start(); + + // Start instance status message delegator + InstanceStatusEventMessageDelegator delegator = + new InstanceStatusEventMessageDelegator(); + Thread tdelegator = new Thread(delegator); + tdelegator.start(); + + // Register cloud controller service + BundleContext bundleContext = context.getBundleContext(); + bundleContext.registerService(CloudControllerService.class.getName(), + new CloudControllerServiceImpl(), null); + + if (log.isInfoEnabled()) { + log.info("Scheduling tasks"); + } + + TopologySynchronizerTaskScheduler.schedule(ServiceReferenceHolder + .getInstance().getTaskService()); + + } catch (Throwable e) { + log.error( + "******* Cloud Controller Service bundle is failed to activate ****", + e); + } + } + + protected void setTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Setting the Task Service"); + } + ServiceReferenceHolder.getInstance().setTaskService(taskService); + } + + protected void unsetTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting the Task Service"); + } + ServiceReferenceHolder.getInstance().setTaskService(null); + } + protected void setRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("Setting the Registry Service"); } - - try { - UserRegistry registry = registryService.getGovernanceSystemRegistry(); - ServiceReferenceHolder.getInstance() - .setRegistry(registry); - } catch (RegistryException e) { - String msg = "Failed when retrieving Governance System Registry."; - log.error(msg, e); - throw new CloudControllerException(msg, e); - } + + try { + UserRegistry registry = registryService + .getGovernanceSystemRegistry(); + ServiceReferenceHolder.getInstance().setRegistry(registry); + } catch (RegistryException e) { + String msg = "Failed when retrieving Governance System Registry."; + log.error(msg, e); + throw new CloudControllerException(msg, e); --- End diff -- Log and throw anti pattern
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---