diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java index b2e1529f40..6bdaa5fee5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -383,7 +383,7 @@ public class DeviceManagementServiceComponent { bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null); /* Registering DeviceState Filter Service */ - DeviceStatusManagementService deviceStatusManagemntService = new DeviceStatusManagementServiceImpl(); + DeviceStatusManagementService deviceStatusManagemntService = DeviceStatusManagementServiceImpl.getInstance(); DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService); try { deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java index 956e65d851..10ffe750f5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java @@ -48,15 +48,24 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class); + private static DeviceStatusManagementServiceImpl instance; + private final MetadataDAO metadataDAO; private final Gson gson; - public DeviceStatusManagementServiceImpl() { + private DeviceStatusManagementServiceImpl() { this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); this.gson = new Gson(); } + public static synchronized DeviceStatusManagementServiceImpl getInstance() { + if (instance == null) { + instance = new DeviceStatusManagementServiceImpl(); + } + return instance; + } + @Override public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException { try { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/search/DeviceDetails.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/search/DeviceDetails.java index 8d6a4a5673..a7d3a06eb8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/search/DeviceDetails.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/search/DeviceDetails.java @@ -43,7 +43,7 @@ public class DeviceDetails extends BaseDeviceManagementTest { DeviceManagementProviderService deviceManagementProviderService = new DeviceManagementProviderServiceImpl(); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProviderService); - DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); + DeviceStatusManagementService deviceStatusManagementService = DeviceStatusManagementServiceImpl.getInstance(); DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); } diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java index fa2f26c972..10d02e699a 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java @@ -66,7 +66,7 @@ public class TenantMgtServiceComponent { componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.class.getName(), whiteLabelManagementService, null); TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); - DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); + DeviceStatusManagementService deviceStatusManagementService = DeviceStatusManagementServiceImpl.getInstance(); componentContext.getBundleContext().registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagementService, null); TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);