From aa8de8cb23df52ba41950f862e828d8345be7144 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 19 Jun 2015 14:23:32 +0530 Subject: [PATCH] Add all registerd devices to newly registerd plugin listner --- .../DeviceManagementServiceComponent.java | 19 ++++++++++--------- .../DeviceManagementProviderServiceImpl.java | 7 ++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 2382cd1946..eed957a493 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -24,6 +24,7 @@ import org.osgi.service.component.ComponentContext; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.license.mgt.License; @@ -101,6 +102,7 @@ public class DeviceManagementServiceComponent { private static final Object LOCK = new Object(); private static List listeners = new ArrayList(); + private static List deviceManagers = new ArrayList(); protected void activate(ComponentContext componentContext) { try { @@ -152,6 +154,9 @@ public class DeviceManagementServiceComponent { public static void registerPluginInitializationListener(PluginInitializationListener listener) { listeners.add(listener); + for(DeviceManagementService deviceManagementService:deviceManagers){ + listener.registerDeviceManagementService(deviceManagementService); + } } private void initLicenseManager() throws LicenseManagementException { @@ -184,11 +189,9 @@ public class DeviceManagementServiceComponent { } /* Registering Device Management Service */ BundleContext bundleContext = componentContext.getBundleContext(); - DeviceManagementProviderService deviceManagementProvider = - new DeviceManagementProviderServiceImpl(this.getPluginRepository()); + DeviceManagementProviderService deviceManagementProvider = new DeviceManagementProviderServiceImpl(); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); - bundleContext.registerService(DeviceManagementProviderService.class.getName(), - deviceManagementProvider, null); + bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null); APIPublisherService publisher = new APIPublisherServiceImpl(); DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher); @@ -200,12 +203,9 @@ public class DeviceManagementServiceComponent { bundleContext.registerService(ApplicationManager.class.getName(), new ApplicationManagementServiceImpl(), null); } - private void setupDeviceManagementSchema(DataSourceConfig config) - throws DeviceManagementException { - DeviceManagementSchemaInitializer initializer = - new DeviceManagementSchemaInitializer(config); + private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { + DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config); log.info("Initializing device management repository database schema"); - try { initializer.createRegistryDatabase(); } catch (Exception e) { @@ -238,6 +238,7 @@ public class DeviceManagementServiceComponent { log.debug("Setting Device Management Service Provider: '" + deviceManagementService.getProviderType() + "'"); } + deviceManagers.add(deviceManagementService); for (PluginInitializationListener listener : listeners) { listener.registerDeviceManagementService(deviceManagementService); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 32d3e61bef..a480385016 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -55,14 +55,15 @@ public class DeviceManagementProviderServiceImpl implements private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); public DeviceManagementProviderServiceImpl() { - /* Registering a listener to retrieve events when some device management service plugin is installed after - * the component is done getting initialized */ - DeviceManagementServiceComponent.registerPluginInitializationListener(this); this.pluginRepository = new DeviceManagementPluginRepository(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); + + /* Registering a listener to retrieve events when some device management service plugin is installed after + * the component is done getting initialized */ + DeviceManagementServiceComponent.registerPluginInitializationListener(this); } @Override