Skip to content

Commit

Permalink
Fix start error.
Browse files Browse the repository at this point in the history
  • Loading branch information
KomachiSion committed May 11, 2023
1 parent f0336b8 commit 5897a61
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.alibaba.nacos.sys.utils.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void removeConfigInfoByIdsAtomic(final String ids) {
MapperContext context = new MapperContext();
context.putWhereParameter(FieldConstant.IDS, paramList);
MapperResult result = configInfoMapper.removeConfigInfoByIdsAtomic(context);
EmbeddedStorageContextHolder.addSqlContext(result.getSql(), result.getParamList());
EmbeddedStorageContextHolder.addSqlContext(result.getSql(), result.getParamList().toArray());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import com.alibaba.nacos.common.spi.NacosServiceLoader;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.config.constants.ConfigChangeConstants;
import com.alibaba.nacos.plugin.config.constants.ConfigChangePointCutTypes;
import com.alibaba.nacos.plugin.config.spi.ConfigChangePluginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Collection;
import java.util.PriorityQueue;
import java.util.Optional;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand All @@ -37,38 +36,39 @@
* @author liyunfei
*/
public class ConfigChangePluginManager {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigChangePluginManager.class);

private static final Integer PLUGIN_SERVICE_COUNT = ConfigChangeConstants.getPluginServiceCount();

private static final Integer PLUGIN_SERVICE_COUNT = 2;
private static final Integer POINT_CUT_TYPE_COUNT = ConfigChangePointCutTypes.values().length;

/**
* The relationship of serviceType and {@link ConfigChangePluginService} ,default capacity is the count of plugin
* service.
*/
private static Map<String, ConfigChangePluginService> configChangeServiceMap = new ConcurrentHashMap<>(
private static final Map<String, ConfigChangePluginService> CONFIG_CHANGE_PLUGIN_SERVICE_MAP = new ConcurrentHashMap<>(
PLUGIN_SERVICE_COUNT);

/**
* The relationship of config change pointcut type and the queue of {@link ConfigChangePluginService} will pointcut it,
* default capacity is the count of pointcutTypes.
* The relationship of config change pointcut type and the queue of {@link ConfigChangePluginService} will pointcut
* it, default capacity is the count of pointcutTypes.
*/
private static Map<ConfigChangePointCutTypes, PriorityQueue<ConfigChangePluginService>> priorityQueueMap = new ConcurrentHashMap<>(
POINT_CUT_TYPE_COUNT);

private static final ConfigChangePluginManager INSTANCE = new ConfigChangePluginManager();

private ConfigChangePluginManager() {
loadConfigChangeServices();
}

/**
* Load all config change plugin services by spi.
*/
private static void loadConfigChangeServices() {
Collection<ConfigChangePluginService> configChangePluginServices = NacosServiceLoader.load(ConfigChangePluginService.class);
Collection<ConfigChangePluginService> configChangePluginServices = NacosServiceLoader
.load(ConfigChangePluginService.class);
// load all config change plugin by spi
for (ConfigChangePluginService each : configChangePluginServices) {
if (StringUtils.isEmpty(each.getServiceType())) {
Expand All @@ -77,54 +77,57 @@ private static void loadConfigChangeServices() {
each.getClass().getName(), each.getClass());
continue;
}
configChangeServiceMap.put(each.getServiceType(), each);
CONFIG_CHANGE_PLUGIN_SERVICE_MAP.put(each.getServiceType(), each);
LOGGER.info("[ConfigChangePluginManager] Load {}({}) ConfigChangeServiceName({}) successfully.",
each.getClass().getName(), each.getClass(), each.getServiceType());
// map the relationship of pointcut and plugin service
addPluginServiceByPointCut(each);
}
}

public static ConfigChangePluginManager getInstance() {
return INSTANCE;
}

/**
* Dynamic get any pluginServiceImpl.
*
* @param serviceType plugin service type.
* @return
*/
public Optional<ConfigChangePluginService> findPluginServiceImpl(String serviceType) {
return Optional.ofNullable(configChangeServiceMap.get(serviceType));
return Optional.ofNullable(CONFIG_CHANGE_PLUGIN_SERVICE_MAP.get(serviceType));
}

/**
* Dynamic add new ConfigChangeService.
*
* @param configChangePluginService ConfigChangeService.
* @return
*/
public static synchronized boolean join(ConfigChangePluginService configChangePluginService) {
configChangeServiceMap.putIfAbsent(configChangePluginService.getServiceType(), configChangePluginService);
CONFIG_CHANGE_PLUGIN_SERVICE_MAP
.putIfAbsent(configChangePluginService.getServiceType(), configChangePluginService);
addPluginServiceByPointCut(configChangePluginService);
return true;
}

/**
* Get the plugin service queue of the pointcut method.
*
* @param pointcutName pointcut method name,detail see {@link ConfigChangePointCutTypes}.
* @return
*/
public static PriorityQueue<ConfigChangePluginService> findPluginServiceQueueByPointcut(ConfigChangePointCutTypes pointcutName) {
public static PriorityQueue<ConfigChangePluginService> findPluginServiceQueueByPointcut(
ConfigChangePointCutTypes pointcutName) {
return priorityQueueMap.getOrDefault(pointcutName, new PriorityQueue<>());
}

private static boolean addPluginServiceByPointCut(ConfigChangePluginService configChangePluginService) {
ConfigChangePointCutTypes[] pointcutNames = configChangePluginService.pointcutMethodNames();
for (ConfigChangePointCutTypes name : pointcutNames) {
PriorityQueue<ConfigChangePluginService> configChangePluginServicePriorityQueue = priorityQueueMap.get(name);
PriorityQueue<ConfigChangePluginService> configChangePluginServicePriorityQueue = priorityQueueMap
.get(name);
if (configChangePluginServicePriorityQueue == null) {
configChangePluginServicePriorityQueue = new PriorityQueue<>(PLUGIN_SERVICE_COUNT,
Comparator.comparingInt(ConfigChangePluginService::getOrder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,21 @@

package com.alibaba.nacos.plugin.config.constants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Config change plugin service constants.
*
* @author liyunfei
*/
public class ConfigChangeConstants {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigChangeConstants.class);

/**
* The relationship of config change plugin service name and its pointcuts.
*/
private static final Map<String, ConfigChangePointCutTypes[]> POINTCUTS_MAP = new ConcurrentHashMap<String, ConfigChangePointCutTypes[]>();

public static final String NACOS_CORE_CONFIG_PLUGIN_PREFIX = "nacos.core.config.plugin.";

public static final String POINT_CUT_NAME = "CONFIG_CHANGE_POINT_CUT_TYPES_TYPES";

public static final String PLUGIN_PROPERTIES = "pluginProperties";

/**
* The actual config method args.
*/
public static final String ORIGINAL_ARGS = "originalArgs";

private static Integer pluginServiceCount = 0;

// Load config pointcuts to each config change plugin services.
static {
Class[] innerClasses = ConfigChangeConstants.class.getDeclaredClasses();
for (Class clazz : innerClasses) {
try {
POINTCUTS_MAP.put(clazz.getSimpleName().toLowerCase(Locale.ROOT),
(ConfigChangePointCutTypes[]) clazz.getField(POINT_CUT_NAME).get(null));
pluginServiceCount++;
} catch (NoSuchFieldException | IllegalAccessException e) {
LOGGER.warn(
"[{}] Load config change plugin service to relevant pointcuts failed,please check {} at {} ",
ConfigChangeConstants.class, POINT_CUT_NAME, clazz);
}
}
}

public static ConfigChangePointCutTypes[] getPointcuts(String serviceType) {
return POINTCUTS_MAP.get(serviceType);
}

public static Integer getPluginServiceCount() {
return pluginServiceCount;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public interface ConfigChangePluginService {
*
* @return array of pointcut the methods
*/
default ConfigChangePointCutTypes[] pointcutMethodNames() {
return ConfigChangeConstants.getPointcuts(getServiceType());
}
ConfigChangePointCutTypes[] pointcutMethodNames();

}

0 comments on commit 5897a61

Please sign in to comment.