Implement Singleton Pattern for DeviceStatusManagementServiceImpl

pull/384/head
Pramila Niroshan 5 months ago
parent 195c48c85e
commit 3bf10445a9

@ -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);

@ -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 {

@ -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);
}

@ -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);

Loading…
Cancel
Save