Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sentinel-spring-webmvc-v6x-adapter #3355

Open
wants to merge 11 commits into
base: 1.8
Choose a base branch
from
Prev Previous commit
add BlockFallbackConfigManager.loadConfig
robberphex committed Mar 1, 2024
commit 00a1e4bdd5c3fa9c493115b90c6e7e13a3487a39
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.alibaba.csp.sentinel.setting.fallback;

import com.alibaba.csp.sentinel.property.DynamicSentinelProperty;
import com.alibaba.csp.sentinel.property.SentinelProperty;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @since 1.8.8
*/
public class BlockFallbackConfigManager {

/**
@@ -11,6 +18,9 @@ public class BlockFallbackConfigManager {
private volatile Map<String, Map<Integer, BlockFallbackConfig<BlockFallbackConfig.WebBlockFallbackBehavior>>> webFallbackConfigMap
= new HashMap<String, Map<Integer, BlockFallbackConfig<BlockFallbackConfig.WebBlockFallbackBehavior>>>();

private SentinelProperty<List<BlockFallbackConfig<Object>>> currentProperty
= new DynamicSentinelProperty<List<BlockFallbackConfig<Object>>>();

private static class InstanceHolder {
private static final BlockFallbackConfigManager INSTANCE = new BlockFallbackConfigManager();
}
@@ -19,8 +29,20 @@ public static BlockFallbackConfigManager getInstance() {
return BlockFallbackConfigManager.InstanceHolder.INSTANCE;
}

public BlockFallbackConfig<BlockFallbackConfig.WebBlockFallbackBehavior> getWebFallbackConfig(String resource,
Class<?> exceptionClazz) {
/**
* Load new block fallback config, which will replace existing config.
*
* @param configList new config list to load
* @return whether the config was actually updated
*/
public boolean loadConfig(List<BlockFallbackConfig<Object>> configList) {
return currentProperty.updateValue(configList);
}

public BlockFallbackConfig<BlockFallbackConfig.WebBlockFallbackBehavior> getWebFallbackConfig(
String resource,
Class<?> exceptionClazz
) {
if (resource == null || exceptionClazz == null) {
return null;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
* Copyright 1999-2024 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.
@@ -16,12 +16,11 @@
package com.alibaba.csp.sentinel.setting.fallback;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;

/**
* @author Eric Zhao
* @author guanyu
* @since 1.8.2
* @since 1.8.8
*/
public final class BlockFallbackUtils {

@@ -30,18 +29,13 @@ public static BlockFallbackConfig.WebBlockFallbackBehavior getFallbackBehavior(S
return null;
}
BlockFallbackConfig<BlockFallbackConfig.WebBlockFallbackBehavior> c;
// 系统保护规则特殊处理,取这个约定好的名称
if (ex instanceof SystemBlockException) {
c = BlockFallbackConfigManager.getInstance().getWebFallbackConfig(BlockFallbackConstants.SYSTEM_RESOURCE,
ex.getClass());
} else {
c = BlockFallbackConfigManager.getInstance().getWebFallbackConfig(resource, ex.getClass());
}
c = BlockFallbackConfigManager.getInstance().getWebFallbackConfig(resource, ex.getClass());
if (c == null) {
return null;
}
return c.getFallbackBehavior();
}

private BlockFallbackUtils() {}
private BlockFallbackUtils() {
}
}
Loading