forked from alibaba/Sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update parameter flow rule to adapt to cluster mode and extract rule …
…util class - Update ParamFlowRule to support cluster mode - Add `ParamFlowClusterConfig` to provide cluster mode items for the rule - Update ParamFlowChecker to support cluster flow mode - Extract ParamFlowRuleUtil class - Change type of `flowId` from Integer to Long Signed-off-by: Eric Zhao <[email protected]>
- Loading branch information
Showing
10 changed files
with
419 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParamFlowClusterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.csp.sentinel.slots.block.flow.param; | ||
|
||
import com.alibaba.csp.sentinel.slots.block.ClusterRuleConstant; | ||
|
||
/** | ||
* Parameter flow rule config in cluster mode. | ||
* | ||
* @author Eric Zhao | ||
* @since 1.4.0 | ||
*/ | ||
public class ParamFlowClusterConfig { | ||
|
||
/** | ||
* Global unique ID. | ||
*/ | ||
private Long flowId; | ||
|
||
/** | ||
* Threshold type (average by local value or global value). | ||
*/ | ||
private int thresholdType = ClusterRuleConstant.FLOW_THRESHOLD_AVG_LOCAL; | ||
private boolean fallbackToLocalWhenFail = false; | ||
|
||
public Long getFlowId() { | ||
return flowId; | ||
} | ||
|
||
public ParamFlowClusterConfig setFlowId(Long flowId) { | ||
this.flowId = flowId; | ||
return this; | ||
} | ||
|
||
public int getThresholdType() { | ||
return thresholdType; | ||
} | ||
|
||
public ParamFlowClusterConfig setThresholdType(int thresholdType) { | ||
this.thresholdType = thresholdType; | ||
return this; | ||
} | ||
|
||
public boolean isFallbackToLocalWhenFail() { | ||
return fallbackToLocalWhenFail; | ||
} | ||
|
||
public ParamFlowClusterConfig setFallbackToLocalWhenFail(boolean fallbackToLocalWhenFail) { | ||
this.fallbackToLocalWhenFail = fallbackToLocalWhenFail; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { return true; } | ||
if (o == null || getClass() != o.getClass()) { return false; } | ||
|
||
ParamFlowClusterConfig that = (ParamFlowClusterConfig)o; | ||
|
||
if (thresholdType != that.thresholdType) { return false; } | ||
if (fallbackToLocalWhenFail != that.fallbackToLocalWhenFail) { return false; } | ||
return flowId != null ? flowId.equals(that.flowId) : that.flowId == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = flowId != null ? flowId.hashCode() : 0; | ||
result = 31 * result + thresholdType; | ||
result = 31 * result + (fallbackToLocalWhenFail ? 1 : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ParamFlowClusterConfig{" + | ||
"flowId=" + flowId + | ||
", thresholdType=" + thresholdType + | ||
", fallbackToLocalWhenFail=" + fallbackToLocalWhenFail + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.