From 9ef6cfc1e6549a356933e7bc243a46adf0a09e4b Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 10 Feb 2021 14:48:20 +0530 Subject: [PATCH] Move executor pool to the DeviceManagementDataHolder --- .../config/EventConfigurationProviderServiceImpl.java | 6 ++---- .../mgt/core/event/config/EventOperationExecutor.java | 9 --------- .../mgt/core/internal/DeviceManagementDataHolder.java | 10 ++++++++++ .../internal/DeviceManagementServiceComponent.java | 4 ++++ .../service/GroupManagementProviderServiceImpl.java | 6 ++++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java index 75e0439074f..b2fe4ede22a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java @@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO; import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import java.sql.SQLException; import java.util.ArrayList; @@ -49,8 +50,6 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration public EventConfigurationProviderServiceImpl() { eventConfigDAO = DeviceManagementDAOFactory.getEventConfigDAO(); - EventOperationTaskConfiguration eventConfig = DeviceConfigurationManager.getInstance() - .getDeviceManagementConfig().getEventOperationTaskConfiguration(); } @Override @@ -249,7 +248,6 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration List groupIds) { GeoFenceEventOperationManager geoFenceEventOperationManager = new GeoFenceEventOperationManager(eventType, tenantId, null); EventOperationExecutor executor = geoFenceEventOperationManager.getEventOperationExecutor(groupIds, eventMeta); - ExecutorService executorService = Executors.newFixedThreadPool(50); - executorService.submit(executor); + DeviceManagementDataHolder.getInstance().getEventConfigExecutors().submit(executor); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java index dc8725f2504..aa40af5025a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java @@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.core.event.config; import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.json.JSONArray; -import org.json.JSONObject; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -36,30 +34,23 @@ import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService; -import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO; -import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.GeofenceDAO; -import org.wso2.carbon.device.mgt.core.geo.task.EventCreateCallback; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 37a9323787a..818df70b490 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -50,6 +50,7 @@ import org.wso2.carbon.utils.ConfigurationContextService; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutorService; public class DeviceManagementDataHolder { @@ -79,6 +80,7 @@ public class DeviceManagementDataHolder { private EventConfigurationProviderService eventConfigurationService; private GeoLocationProviderService geoLocationProviderService; private GeoFenceEventOperationManager geoFenceEventOperationManager; + private ExecutorService eventConfigExecutors; private final Map deviceStatusTaskPluginConfigs = Collections.synchronizedMap( new HashMap<>()); @@ -328,4 +330,12 @@ public class DeviceManagementDataHolder { public void setGeoFenceEventOperationManager(GeoFenceEventOperationManager geoFenceEventOperationManager) { this.geoFenceEventOperationManager = geoFenceEventOperationManager; } + + public ExecutorService getEventConfigExecutors() { + return eventConfigExecutors; + } + + public void setEventConfigExecutors(ExecutorService eventConfigExecutors) { + this.eventConfigExecutors = eventConfigExecutors; + } } 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 9064a9d9ec9..5bd7a3730b2 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 @@ -89,6 +89,7 @@ import org.wso2.carbon.utils.ConfigurationContextService; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -372,6 +373,9 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setDeviceInformationManager(deviceInformationManager); bundleContext.registerService(SearchManagerService.class, new SearchManagerServiceImpl(), null); + + ExecutorService executorService = Executors.newFixedThreadPool(50); + DeviceManagementDataHolder.getInstance().setEventConfigExecutors(executorService); } private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 1e19cbb42ba..6ec253a1960 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -1068,9 +1068,11 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GeoFenceEventOperationManager eventManager = new GeoFenceEventOperationManager(eventOperationCode, tenantId, null); GroupAssignmentEventOperationExecutor eventOperationExecutor = eventManager .getGroupAssignmentEventExecutor(groupId, deviceIdentifiers); - ExecutorService executorService = Executors.newFixedThreadPool(50); if (eventOperationExecutor != null) { - executorService.submit(eventOperationExecutor); + ExecutorService eventConfigExecutors = DeviceManagementDataHolder.getInstance().getEventConfigExecutors(); + if (eventConfigExecutors != null) { + eventConfigExecutors.submit(eventOperationExecutor); + } } else { if (log.isDebugEnabled()) { log.debug("Ignoring event creation since not enabled. Tenant id: " + tenantId + " Group Id: " + groupId);