1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

fix #716, the conflicts of SlotChainBuilder SPI

This commit is contained in:
fangjian0423
2019-06-24 16:18:17 +08:00
parent 0b85739544
commit 5358b2c1a8
7 changed files with 218 additions and 110 deletions

View File

@@ -6,8 +6,6 @@ import java.util.Optional;
import org.springframework.cloud.alibaba.sentinel.datasource.config.AbstractDataSourceProperties;
import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
@@ -46,11 +44,13 @@ public enum RuleType {
/**
* gateway flow
*/
GW_FLOW("gw-flow", GatewayFlowRule.class),
GW_FLOW("gw-flow",
"com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule"),
/**
* api
*/
GW_API_GROUP("gw-api-group", ApiDefinition.class);
GW_API_GROUP("gw-api-group",
"com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition");
/**
* alias for {@link AbstractRule}
@@ -60,19 +60,39 @@ public enum RuleType {
/**
* concrete {@link AbstractRule} class
*/
private final Class clazz;
private Class clazz;
/**
* concrete {@link AbstractRule} class name
*/
private String clazzName;
RuleType(String name, Class clazz) {
this.name = name;
this.clazz = clazz;
}
RuleType(String name, String clazzName) {
this.name = name;
this.clazzName = clazzName;
}
public String getName() {
return name;
}
public Class getClazz() {
return clazz;
if (clazz != null) {
return clazz;
}
else {
try {
return Class.forName(clazzName);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
public static Optional<RuleType> getByName(String name) {

View File

@@ -12,8 +12,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.alibaba.sentinel.datasource.RuleType;
import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
@@ -57,11 +55,13 @@ public abstract class SentinelConverter<T extends Object>
Collection<Object> ruleCollection;
// hard code
if (ruleClass == GatewayFlowRule.class || ruleClass == ApiDefinition.class) {
ruleCollection = new HashSet<>();
if (ruleClass == FlowRule.class || ruleClass == DegradeRule.class
|| ruleClass == SystemRule.class || ruleClass == AuthorityRule.class
|| ruleClass == ParamFlowRule.class) {
ruleCollection = new ArrayList<>();
}
else {
ruleCollection = new ArrayList<>();
ruleCollection = new HashSet<>();
}
if (StringUtils.isEmpty(source)) {