From 8f83027e742cfc8f2929122bfba014dd644f0e7f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 26 Mar 2015 20:35:32 +0530 Subject: [PATCH 1/2] Making plugin registration deferred till the core completely registered --- .../DeviceManagementServiceComponent.java | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 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 29082cc0c5..2cc370a15c 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 @@ -53,6 +53,9 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; +import java.util.ArrayList; +import java.util.List; + /** * @scr.component name="org.wso2.carbon.device.manager" immediate="true" * @scr.reference name="user.realmservice.default" @@ -85,6 +88,10 @@ public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); + private static final Object LOCK = new Object(); + private boolean isInitialized; + private List deviceManagers = new ArrayList(); + protected void activate(ComponentContext componentContext) { try { if (log.isDebugEnabled()) { @@ -132,6 +139,13 @@ public class DeviceManagementServiceComponent { this.setupDefaultLicenses(licenseConfig); } + synchronized (LOCK) { + for (DeviceManager deviceManager : deviceManagers) { + this.registerDeviceManagementProvider(deviceManager); + } + this.isInitialized = true; + } + /* Registering declarative service instances exposed by DeviceManagementServiceComponent */ this.registerServices(componentContext); @@ -139,8 +153,7 @@ public class DeviceManagementServiceComponent { log.debug("Device management core bundle has been successfully initialized"); } } catch (Throwable e) { - String msg = "Error occurred while initializing device management core bundle"; - log.error(msg, e); + log.error("Error occurred while initializing device management core bundle", e); } } @@ -163,10 +176,8 @@ public class DeviceManagementServiceComponent { bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null); - /* Registering App Management service */ - bundleContext.registerService(AppManager.class.getName(), - new AppManagementServiceImpl(), null); + bundleContext.registerService(AppManager.class.getName(), new AppManagementServiceImpl(), null); } private void setupDeviceManagementSchema(DataSourceConfig config) @@ -193,25 +204,34 @@ public class DeviceManagementServiceComponent { for (License license : licenseConfig.getLicenses()) { License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage()); if (extLicense == null) { - licenseManager.addLicense(license.getName(), license);; + licenseManager.addLicense(license.getName(), license); } } } + private void registerDeviceManagementProvider(DeviceManager deviceManager) { + try { + this.getPluginRepository().addDeviceManagementProvider(deviceManager); + } catch (DeviceManagementException e) { + log.error("Error occurred while adding device management provider '" + + deviceManager.getProviderType() + "'"); + } + } + /** * Sets Device Manager service. * * @param deviceManager An instance of DeviceManager */ protected void setDeviceManager(DeviceManager deviceManager) { - if (log.isDebugEnabled()) { - log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); - } - try { - this.getPluginRepository().addDeviceManagementProvider(deviceManager); - } catch (DeviceManagementException e) { - log.error("Error occurred while adding device management provider '" + - deviceManager.getProviderType() + "'"); + if (log.isDebugEnabled()) { + log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); + } + synchronized (LOCK) { + if (isInitialized) { + this.registerDeviceManagementProvider(deviceManager); + } + deviceManagers.add(deviceManager); } } From 53d6dcb8ef33d815a754e9e143ac38b10d14d2a3 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 26 Mar 2015 21:59:55 +0530 Subject: [PATCH 2/2] Fixing build failures caused by an improper parent pom config --- .../pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index de3e9b42f4..19c0af1521 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt - device-mgt-feature + webapp-authenticator-framework-feature 0.9.2-SNAPSHOT ../pom.xml