DefaultProtectedStrategy implements ProviderProtectedStrategy, StatisticCallback { @Override public Response call(Request request, Provider<?> provider) { int maxThread = provider.getUrl().getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue()); String requestKey = MotanFrameworkUtil.getFullMethodString(request); try { int requestCounter = incrCounter(requestKey, requestCounters); int totalCounter = incrTotalCounter(); if (isAllowRequest(requestCounter, totalCounter, maxThread)) { return provider.call(request); } else { return reject(request.getInterfaceName() + "." + request.getMethodName(), requestCounter, totalCounter, maxThread, request); } } finally { decrTotalCounter(); decrCounter(requestKey, requestCounters); } } DefaultProtectedStrategy(); @Override void setMethodCounter(AtomicInteger methodCounter); @Override Response call(Request request, Provider<?> provider); boolean isAllowRequest(int requestCounter, int totalCounter, int maxThread); @Override String statisticCallback();  }
@Test public void testCall() { DefaultProtectedStrategy defaultProtectedStrategy = new DefaultProtectedStrategy(); defaultProtectedStrategy.setMethodCounter(new AtomicInteger(1)); Provider<ProviderA> providerA = new DefaultProvider<ProviderA>(new ProviderAImpl(), new URL("injvm", "localhost", 0, ProviderA.class.getName()), ProviderA.class); DefaultRequest requestA = new DefaultRequest(); requestA.setInterfaceName(com.weibo.api.motan.transport.ProviderA.class.getName()); requestA.setMethodName("providerA"); requestA.setParamtersDesc(ReflectUtil.EMPTY_PARAM); Response response = defaultProtectedStrategy.call(requestA, providerA); Assert.assertEquals(providerA.getImpl().providerA(), response.getValue()); }