mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing issues in plugin initialization as a result of certain plugins getting initialized after the device management component is done getting configured
This commit is contained in:
parent
2526d87c21
commit
a2dc916fd0
@ -108,6 +108,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
private static final Object LOCK = new Object();
|
private static final Object LOCK = new Object();
|
||||||
private boolean isInitialized;
|
private boolean isInitialized;
|
||||||
private List<DeviceManagementService> deviceManagementServices = new ArrayList<DeviceManagementService>();
|
private List<DeviceManagementService> deviceManagementServices = new ArrayList<DeviceManagementService>();
|
||||||
|
private static List<PluginInitializationListener> listeners = new ArrayList<PluginInitializationListener>();
|
||||||
|
|
||||||
protected void activate(ComponentContext componentContext) {
|
protected void activate(ComponentContext componentContext) {
|
||||||
try {
|
try {
|
||||||
@ -168,6 +169,10 @@ public class DeviceManagementServiceComponent {
|
|||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
private void initLicenseManager() throws LicenseManagementException {
|
private void initLicenseManager() throws LicenseManagementException {
|
||||||
LicenseConfigurationManager.getInstance().initConfig();
|
LicenseConfigurationManager.getInstance().initConfig();
|
||||||
LicenseConfig licenseConfig =
|
LicenseConfig licenseConfig =
|
||||||
@ -242,6 +247,9 @@ public class DeviceManagementServiceComponent {
|
|||||||
private void registerDeviceManagementProvider(DeviceManagementService deviceManagementService) {
|
private void registerDeviceManagementProvider(DeviceManagementService deviceManagementService) {
|
||||||
try {
|
try {
|
||||||
this.getPluginRepository().addDeviceManagementProvider(deviceManagementService);
|
this.getPluginRepository().addDeviceManagementProvider(deviceManagementService);
|
||||||
|
for (PluginInitializationListener listener : listeners) {
|
||||||
|
listener.notify(deviceManagementService);
|
||||||
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error("Error occurred while adding device management provider '" +
|
log.error("Error occurred while adding device management provider '" +
|
||||||
deviceManagementService.getProviderType() + "'");
|
deviceManagementService.getProviderType() + "'");
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
|
||||||
|
public interface PluginInitializationListener {
|
||||||
|
|
||||||
|
void notify(DeviceManagementService deviceManagementService);
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
|||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
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.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages;
|
import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages;
|
||||||
@ -34,7 +35,9 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|||||||
import org.wso2.carbon.device.mgt.core.dto.*;
|
import org.wso2.carbon.device.mgt.core.dto.*;
|
||||||
import org.wso2.carbon.device.mgt.core.email.EmailConstants;
|
import org.wso2.carbon.device.mgt.core.email.EmailConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -43,7 +46,8 @@ import java.net.URLEncoder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService {
|
public class DeviceManagementProviderServiceImpl implements
|
||||||
|
DeviceManagementProviderService, PluginInitializationListener {
|
||||||
|
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
@ -53,6 +57,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
||||||
|
|
||||||
public DeviceManagementProviderServiceImpl(DeviceManagementRepository pluginRepository) {
|
public DeviceManagementProviderServiceImpl(DeviceManagementRepository pluginRepository) {
|
||||||
|
/* Registering a listener to retrieve events when some device management service plugin is installed after
|
||||||
|
* the component is done getting initialized */
|
||||||
|
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
|
||||||
|
|
||||||
this.pluginRepository = pluginRepository;
|
this.pluginRepository = pluginRepository;
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
@ -627,4 +635,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notify(DeviceManagementService deviceManagementService) {
|
||||||
|
try {
|
||||||
|
pluginRepository.addDeviceManagementProvider(deviceManagementService);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while registering device management plugin '" +
|
||||||
|
deviceManagementService.getProviderType() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user