-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
200 additions
and
128 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
56 changes: 56 additions & 0 deletions
56
...ient-redis/src/main/java/com/alibaba/csp/sentinel/cluster/redis/RedisClusterFlowSlot.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,56 @@ | ||
package com.alibaba.csp.sentinel.cluster.redis; | ||
|
||
import com.alibaba.csp.sentinel.cluster.redis.config.RedisFlowRuleManager; | ||
import com.alibaba.csp.sentinel.context.Context; | ||
import com.alibaba.csp.sentinel.node.DefaultNode; | ||
import com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot; | ||
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; | ||
import com.alibaba.csp.sentinel.slots.block.BlockException; | ||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; | ||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleChecker; | ||
import com.alibaba.csp.sentinel.util.AssertUtil; | ||
import com.alibaba.csp.sentinel.util.function.Function; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RedisClusterFlowSlot extends AbstractLinkedProcessorSlot<DefaultNode> { | ||
private final FlowRuleChecker checker; | ||
|
||
public RedisClusterFlowSlot() { | ||
this(new FlowRuleChecker()); | ||
} | ||
|
||
RedisClusterFlowSlot(FlowRuleChecker checker) { | ||
AssertUtil.notNull(checker, "flow checker should not be null"); | ||
this.checker = checker; | ||
} | ||
|
||
@Override | ||
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, | ||
boolean prioritized, Object... args) throws Throwable { | ||
checkFlow(resourceWrapper, context, node, count, prioritized); | ||
|
||
fireEntry(context, resourceWrapper, node, count, prioritized, args); | ||
} | ||
|
||
void checkFlow(ResourceWrapper resource, Context context, DefaultNode node, int count, boolean prioritized) | ||
throws BlockException { | ||
checker.checkFlow(ruleProvider, resource, context, node, count, prioritized); | ||
} | ||
|
||
@Override | ||
public void exit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) { | ||
fireExit(context, resourceWrapper, count, args); | ||
} | ||
|
||
private final Function<String, Collection<FlowRule>> ruleProvider = new Function<String, Collection<FlowRule>>() { | ||
@Override | ||
public Collection<FlowRule> apply(String resource) { | ||
// Flow rule map should not be null. | ||
Map<String, List<FlowRule>> flowRules = RedisFlowRuleManager.getFlowRuleMap(); | ||
return flowRules.get(resource); | ||
} | ||
}; | ||
} |
13 changes: 13 additions & 0 deletions
13
...is/src/main/java/com/alibaba/csp/sentinel/cluster/redis/RedisClusterFlowSlotExtender.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,13 @@ | ||
package com.alibaba.csp.sentinel.cluster.redis; | ||
|
||
import com.alibaba.csp.sentinel.slotchain.ProcessorSlotChain; | ||
import com.alibaba.csp.sentinel.slotchain.SlotChainExtender; | ||
|
||
public class RedisClusterFlowSlotExtender implements SlotChainExtender { | ||
|
||
@Override | ||
public ProcessorSlotChain extend(ProcessorSlotChain slotChain) { | ||
slotChain.addLast(new RedisClusterFlowSlot()); | ||
return slotChain; | ||
} | ||
} |
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
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
Oops, something went wrong.