From 0e18ebcf4eb04339db9124cf4667fcf4598d6466 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 19 Jun 2015 17:35:15 +0530 Subject: [PATCH] Synchronize plugin register --- .../DeviceManagementServiceComponent.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 eed957a493..a45280f843 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 @@ -61,6 +61,8 @@ import org.wso2.carbon.user.core.service.RealmService; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; /** * @scr.component name="org.wso2.carbon.device.manager" immediate="true" @@ -153,9 +155,11 @@ public class DeviceManagementServiceComponent { } public static void registerPluginInitializationListener(PluginInitializationListener listener) { - listeners.add(listener); - for(DeviceManagementService deviceManagementService:deviceManagers){ - listener.registerDeviceManagementService(deviceManagementService); + synchronized (LOCK) { + listeners.add(listener); + for (DeviceManagementService deviceManagementService : deviceManagers) { + listener.registerDeviceManagementService(deviceManagementService); + } } } @@ -238,9 +242,11 @@ public class DeviceManagementServiceComponent { log.debug("Setting Device Management Service Provider: '" + deviceManagementService.getProviderType() + "'"); } - deviceManagers.add(deviceManagementService); - for (PluginInitializationListener listener : listeners) { - listener.registerDeviceManagementService(deviceManagementService); + synchronized (LOCK) { + deviceManagers.add(deviceManagementService); + for (PluginInitializationListener listener : listeners) { + listener.registerDeviceManagementService(deviceManagementService); + } } }