Skip to content

Commit

Permalink
Set default FlowRule.grade to RuleConstant.FLOW_GRADE_QPS
Browse files Browse the repository at this point in the history
  • Loading branch information
CarpenterLee committed Jul 27, 2018
1 parent d727f1c commit 5d5b19e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private Map<String, List<AuthorityRule>> loadAuthorityConf(List<AuthorityRule> l
Map<String, List<AuthorityRule>> newRuleMap = new ConcurrentHashMap<String, List<AuthorityRule>>();
for (AuthorityRule rule : list) {
if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.DEFAULT);
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
}

String identity = rule.getResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private Map<String, List<DegradeRule>> loadDegradeConf(List<DegradeRule> list) {

for (DegradeRule rule : list) {
if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.DEFAULT);
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
}

String identity = rule.getResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@
*/
public class FlowRule extends AbstractRule {

public static final String DEFAULT = "default";
public static final String OTHER = "other";
public static final String LIMIT_APP_DEFAULT = "default";
public static final String LIMIT_APP_OTHER = "other";

public FlowRule(){
super();
setLimitApp(LIMIT_APP_DEFAULT);
}

/**
* The threshold type of flow control (0: thread count, 1: QPS).
*/
private int grade;
private int grade = RuleConstant.FLOW_GRADE_QPS;

private double count;

/**
* 0为直接限流;1为关联限流;2为链路限流
*/
private int strategy;
private int strategy = RuleConstant.STRATEGY_DIRECT;

private String refResource;

Expand Down Expand Up @@ -181,7 +186,7 @@ private Node selectNodeByRequesterAndStrategy(String origin, Context context, De
return node;
}

} else if (limitApp.equals(DEFAULT)) {
} else if (LIMIT_APP_DEFAULT.equals(limitApp)) {
if (strategy == RuleConstant.STRATEGY_DIRECT) {
return node.getClusterNode();
}
Expand All @@ -201,7 +206,7 @@ private Node selectNodeByRequesterAndStrategy(String origin, Context context, De
return node;
}

} else if (limitApp.equals(OTHER) && FlowRuleManager.isOtherOrigin(origin, getResource())) {
} else if (LIMIT_APP_OTHER.equals(limitApp) && FlowRuleManager.isOtherOrigin(origin, getResource())) {
if (strategy == RuleConstant.STRATEGY_DIRECT) {
return context.getOriginNode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public int compare(FlowRule o1, FlowRule o2) {
return 0;
}

if (FlowRule.DEFAULT.equals(o1.getLimitApp())) {
if (FlowRule.LIMIT_APP_DEFAULT.equals(o1.getLimitApp())) {
return 1;
} else if (FlowRule.DEFAULT.equals(o2.getLimitApp())) {
} else if (FlowRule.LIMIT_APP_DEFAULT.equals(o2.getLimitApp())) {
return -1;
} else {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static Map<String, List<FlowRule>> loadFlowConf(List<FlowRule> list) {

for (FlowRule rule : list) {
if (StringUtil.isBlank(rule.getLimitApp())) {
rule.setLimitApp(FlowRule.DEFAULT);
rule.setLimitApp(FlowRule.LIMIT_APP_DEFAULT);
}

Controller rater = new DefaultController(rule.getCount(), rule.getGrade());
Expand Down

0 comments on commit 5d5b19e

Please sign in to comment.