public class ProviderProtectedMessageRouter extends ProviderMessageRouter implements StatisticCallback
provider 消息处理分发:支持一定程度的自我防护
1) 如果接口只有一个方法,那么直接return true
2) 如果接口有多个方法,那么如果单个method超过 maxThread / 2 && totalCount > (maxThread * 3 / 4),那么return false;
3) 如果接口有多个方法(4个),同时总的请求数超过 maxThread * 3 / 4,同时该method的请求数超过 maxThead * 1 / 4, 那么return false
4) 其他场景return true
| Modifier and Type | Field and Description |
|---|---|
protected AtomicInteger |
rejectCounter |
protected ConcurrentMap<String,AtomicInteger> |
rejectCounters |
protected ConcurrentMap<String,AtomicInteger> |
requestCounters |
protected AtomicInteger |
totalCounter |
methodCounter, providers| Constructor and Description |
|---|
ProviderProtectedMessageRouter() |
ProviderProtectedMessageRouter(Provider<?> provider) |
| Modifier and Type | Method and Description |
|---|---|
protected Response |
call(Request request,
Provider<?> provider) |
protected boolean |
isAllowRequest(int requestCounter,
int totalCounter,
int maxThread) |
String |
statisticCallback() |
addProvider, getPublicMethodCount, handle, removeProviderprotected ConcurrentMap<String,AtomicInteger> requestCounters
protected ConcurrentMap<String,AtomicInteger> rejectCounters
protected AtomicInteger totalCounter
protected AtomicInteger rejectCounter
public ProviderProtectedMessageRouter()
public ProviderProtectedMessageRouter(Provider<?> provider)
protected Response call(Request request, Provider<?> provider)
call in class ProviderMessageRouterprotected boolean isAllowRequest(int requestCounter,
int totalCounter,
int maxThread)
public String statisticCallback()
statisticCallback in interface StatisticCallbackCopyright © 2020. All rights reserved.