Implement Singleton Pattern for DeviceStatusManagementServiceImpl

fix-subtenat-device-status-issue
Pramila Niroshan 4 months ago
parent 195c48c85e
commit 3bf10445a9

@ -383,7 +383,7 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null); bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null);
/* Registering DeviceState Filter Service */ /* Registering DeviceState Filter Service */
DeviceStatusManagementService deviceStatusManagemntService = new DeviceStatusManagementServiceImpl(); DeviceStatusManagementService deviceStatusManagemntService = DeviceStatusManagementServiceImpl.getInstance();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService); DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService);
try { try {
deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId); deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId);

@ -48,15 +48,24 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class);
private static DeviceStatusManagementServiceImpl instance;
private final MetadataDAO metadataDAO; private final MetadataDAO metadataDAO;
private final Gson gson; private final Gson gson;
public DeviceStatusManagementServiceImpl() { private DeviceStatusManagementServiceImpl() {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
this.gson = new Gson(); this.gson = new Gson();
} }
public static synchronized DeviceStatusManagementServiceImpl getInstance() {
if (instance == null) {
instance = new DeviceStatusManagementServiceImpl();
}
return instance;
}
@Override @Override
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException { public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
try { try {

@ -43,7 +43,7 @@ public class DeviceDetails extends BaseDeviceManagementTest {
DeviceManagementProviderService deviceManagementProviderService = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService deviceManagementProviderService = new DeviceManagementProviderServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProviderService); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProviderService);
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); DeviceStatusManagementService deviceStatusManagementService = DeviceStatusManagementServiceImpl.getInstance();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);
} }

@ -66,7 +66,7 @@ public class TenantMgtServiceComponent {
componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.class.getName(), componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.class.getName(),
whiteLabelManagementService, null); whiteLabelManagementService, null);
TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService);
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); DeviceStatusManagementService deviceStatusManagementService = DeviceStatusManagementServiceImpl.getInstance();
componentContext.getBundleContext().registerService(DeviceStatusManagementService.class.getName(), componentContext.getBundleContext().registerService(DeviceStatusManagementService.class.getName(),
deviceStatusManagementService, null); deviceStatusManagementService, null);
TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);

Loading…
Cancel
Save