mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
update sentinel version to 0.2.0
This commit is contained in:
@@ -34,10 +34,10 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.DataSource;
|
||||
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
|
||||
|
||||
/**
|
||||
* {@link DataSource} Loader
|
||||
* {@link ReadableDataSource} Loader
|
||||
*
|
||||
* @author fangjian
|
||||
*/
|
||||
@@ -50,20 +50,20 @@ public class DataSourceLoader {
|
||||
private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX
|
||||
+ PROPERTIES_RESOURCE_LOCATION;
|
||||
|
||||
private final static ConcurrentMap<String, Class<? extends DataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends DataSource>>(
|
||||
private final static ConcurrentMap<String, Class<? extends ReadableDataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends ReadableDataSource>>(
|
||||
4);
|
||||
|
||||
static void loadAllDataSourceClassesCache() {
|
||||
Map<String, Class<? extends DataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache(
|
||||
Map<String, Class<? extends ReadableDataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache(
|
||||
ALL_PROPERTIES_RESOURCES_LOCATION);
|
||||
|
||||
dataSourceClassesCache.putAll(dataSourceClassesMap);
|
||||
}
|
||||
|
||||
static Map<String, Class<? extends DataSource>> loadAllDataSourceClassesCache(
|
||||
static Map<String, Class<? extends ReadableDataSource>> loadAllDataSourceClassesCache(
|
||||
String resourcesLocation) {
|
||||
|
||||
Map<String, Class<? extends DataSource>> dataSourcesMap = new HashMap<String, Class<? extends DataSource>>(
|
||||
Map<String, Class<? extends ReadableDataSource>> dataSourcesMap = new HashMap<String, Class<? extends ReadableDataSource>>(
|
||||
4);
|
||||
|
||||
ClassLoader classLoader = DataSourceLoader.class.getClassLoader();
|
||||
@@ -102,10 +102,10 @@ public class DataSourceLoader {
|
||||
|
||||
Class<?> dataSourceClass = ClassUtils.resolveClassName(className,
|
||||
classLoader);
|
||||
Assert.isAssignable(DataSource.class, dataSourceClass);
|
||||
Assert.isAssignable(ReadableDataSource.class, dataSourceClass);
|
||||
|
||||
dataSourcesMap.put(type,
|
||||
(Class<? extends DataSource>) dataSourceClass);
|
||||
(Class<? extends ReadableDataSource>) dataSourceClass);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Sentinel DataSource implementation [ type : "
|
||||
@@ -126,10 +126,10 @@ public class DataSourceLoader {
|
||||
return dataSourcesMap;
|
||||
}
|
||||
|
||||
public static Class<? extends DataSource> loadClass(String type)
|
||||
public static Class<? extends ReadableDataSource> loadClass(String type)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
Class<? extends DataSource> dataSourceClass = dataSourceClassesCache.get(type);
|
||||
Class<? extends ReadableDataSource> dataSourceClass = dataSourceClassesCache.get(type);
|
||||
|
||||
if (dataSourceClass == null) {
|
||||
if (dataSourceClassesCache.isEmpty()) {
|
||||
|
@@ -44,20 +44,20 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
|
||||
/**
|
||||
* {@link SentinelDataSource @SentinelDataSource} Post Processor
|
||||
*
|
||||
* @author fangjian
|
||||
* @see com.alibaba.csp.sentinel.datasource.DataSource
|
||||
* @see com.alibaba.csp.sentinel.datasource.ReadableDataSource
|
||||
* @see SentinelDataSource
|
||||
*/
|
||||
public class SentinelDataSourcePostProcessor
|
||||
extends InstantiationAwareBeanPostProcessorAdapter
|
||||
implements MergedBeanDefinitionPostProcessor {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(SentinelDataSourcePostProcessor.class);
|
||||
|
||||
@Autowired
|
||||
@@ -170,8 +170,8 @@ public class SentinelDataSourcePostProcessor
|
||||
for (String propertyName : propertyMap.keySet()) {
|
||||
Field field = ReflectionUtils.findField(targetClass, propertyName);
|
||||
if (field != null) {
|
||||
if (field.getType().isAssignableFrom(ConfigParser.class)) {
|
||||
// ConfigParser get from ApplicationContext
|
||||
if (field.getType().isAssignableFrom(Converter.class)) {
|
||||
// Converter get from ApplicationContext
|
||||
builder.addPropertyReference(propertyName,
|
||||
propertyMap.get(propertyName).toString());
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||
|
||||
/**
|
||||
@@ -14,12 +14,12 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
|
||||
private String namespaceName;
|
||||
private String flowRulesKey;
|
||||
private String defaultFlowRuleValue;
|
||||
private ConfigParser configParser;
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
public ApolloDataSource getObject() throws Exception {
|
||||
return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
|
||||
configParser);
|
||||
converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,11 +51,11 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
|
||||
this.defaultFlowRuleValue = defaultFlowRuleValue;
|
||||
}
|
||||
|
||||
public ConfigParser getConfigParser() {
|
||||
return configParser;
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConfigParser(ConfigParser configParser) {
|
||||
this.configParser = configParser;
|
||||
public void setConverter(Converter Converter) {
|
||||
this.converter = Converter;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
||||
|
||||
/**
|
||||
@@ -19,11 +19,11 @@ public class FileRefreshableDataSourceFactoryBean
|
||||
private String charset;
|
||||
private long recommendRefreshMs;
|
||||
private int bufSize;
|
||||
private ConfigParser configParser;
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
public FileRefreshableDataSource getObject() throws Exception {
|
||||
return new FileRefreshableDataSource(new File(file), configParser,
|
||||
return new FileRefreshableDataSource(new File(file), converter,
|
||||
recommendRefreshMs, bufSize, Charset.forName(charset));
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ public class FileRefreshableDataSourceFactoryBean
|
||||
this.bufSize = bufSize;
|
||||
}
|
||||
|
||||
public ConfigParser getConfigParser() {
|
||||
return configParser;
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConfigParser(ConfigParser configParser) {
|
||||
this.configParser = configParser;
|
||||
public void setConverter(Converter Converter) {
|
||||
this.converter = Converter;
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
||||
|
||||
/**
|
||||
@@ -14,11 +14,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
private String serverAddr;
|
||||
private String groupId;
|
||||
private String dataId;
|
||||
private ConfigParser configParser;
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
public NacosDataSource getObject() throws Exception {
|
||||
return new NacosDataSource(serverAddr, groupId, dataId, configParser);
|
||||
return new NacosDataSource(serverAddr, groupId, dataId, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,11 +50,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public ConfigParser getConfigParser() {
|
||||
return configParser;
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConfigParser(ConfigParser configParser) {
|
||||
this.configParser = configParser;
|
||||
public void setConverter(Converter Converter) {
|
||||
this.converter = Converter;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.ConfigParser;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||
|
||||
/**
|
||||
@@ -19,17 +19,17 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
|
||||
private String groupId;
|
||||
private String dataId;
|
||||
|
||||
private ConfigParser configParser;
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
public ZookeeperDataSource getObject() throws Exception {
|
||||
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
|
||||
// the path will be /{groupId}/{dataId}
|
||||
return new ZookeeperDataSource(serverAddr, groupId, dataId, configParser);
|
||||
// the path will be /{groupId}/{dataId}
|
||||
return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
|
||||
}
|
||||
else {
|
||||
// using path directly
|
||||
return new ZookeeperDataSource(serverAddr, path, configParser);
|
||||
// using path directly
|
||||
return new ZookeeperDataSource(serverAddr, path, converter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,11 +70,11 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public ConfigParser getConfigParser() {
|
||||
return configParser;
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConfigParser(ConfigParser configParser) {
|
||||
this.configParser = configParser;
|
||||
public void setConverter(Converter Converter) {
|
||||
this.converter = Converter;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user