Making plugin registration deferred till the core completely registered

4.x.x
prabathabey 10 years ago
parent 2002c92032
commit 8f83027e74

@ -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.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService; 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.component name="org.wso2.carbon.device.manager" immediate="true"
* @scr.reference name="user.realmservice.default" * @scr.reference name="user.realmservice.default"
@ -85,6 +88,10 @@ public class DeviceManagementServiceComponent {
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
private static final Object LOCK = new Object();
private boolean isInitialized;
private List<DeviceManager> deviceManagers = new ArrayList<DeviceManager>();
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -132,6 +139,13 @@ public class DeviceManagementServiceComponent {
this.setupDefaultLicenses(licenseConfig); this.setupDefaultLicenses(licenseConfig);
} }
synchronized (LOCK) {
for (DeviceManager deviceManager : deviceManagers) {
this.registerDeviceManagementProvider(deviceManager);
}
this.isInitialized = true;
}
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */ /* Registering declarative service instances exposed by DeviceManagementServiceComponent */
this.registerServices(componentContext); this.registerServices(componentContext);
@ -139,8 +153,7 @@ public class DeviceManagementServiceComponent {
log.debug("Device management core bundle has been successfully initialized"); log.debug("Device management core bundle has been successfully initialized");
} }
} catch (Throwable e) { } catch (Throwable e) {
String msg = "Error occurred while initializing device management core bundle"; log.error("Error occurred while initializing device management core bundle", e);
log.error(msg, e);
} }
} }
@ -163,10 +176,8 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null); bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null);
/* Registering App Management service */ /* Registering App Management service */
bundleContext.registerService(AppManager.class.getName(), bundleContext.registerService(AppManager.class.getName(), new AppManagementServiceImpl(), null);
new AppManagementServiceImpl(), null);
} }
private void setupDeviceManagementSchema(DataSourceConfig config) private void setupDeviceManagementSchema(DataSourceConfig config)
@ -193,8 +204,17 @@ public class DeviceManagementServiceComponent {
for (License license : licenseConfig.getLicenses()) { for (License license : licenseConfig.getLicenses()) {
License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage()); License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage());
if (extLicense == null) { 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() + "'");
} }
} }
@ -207,11 +227,11 @@ public class DeviceManagementServiceComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'");
} }
try { synchronized (LOCK) {
this.getPluginRepository().addDeviceManagementProvider(deviceManager); if (isInitialized) {
} catch (DeviceManagementException e) { this.registerDeviceManagementProvider(deviceManager);
log.error("Error occurred while adding device management provider '" + }
deviceManager.getProviderType() + "'"); deviceManagers.add(deviceManager);
} }
} }

Loading…
Cancel
Save