Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnights committed Jun 26, 2017
1 parent a882d43 commit c357080
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package com.weibo.api.motan.transport;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

import com.weibo.api.motan.common.URLParamType;
import com.weibo.api.motan.exception.MotanErrorMsgConstant;
import com.weibo.api.motan.exception.MotanServiceException;
Expand All @@ -30,31 +26,32 @@
import com.weibo.api.motan.util.LoggerUtil;
import com.weibo.api.motan.util.MotanFrameworkUtil;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
* TODO 可配置化策略
*
* <p>
* provider 消息处理分发:支持一定程度的自我防护
*
* <p>
* <pre>
*
*
* 1) 如果接口只有一个方法,那么直接return true
*
* 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
*
*
* </pre>
*
*
* @author maijunsheng
* @version 创建时间:2013-6-7
*
*/
public class ProviderProtectedMessageRouter extends ProviderMessageRouter {
protected ConcurrentMap<String, AtomicInteger> requestCounters = new ConcurrentHashMap<String, AtomicInteger>();
protected AtomicInteger totalCounter = new AtomicInteger(0);



public ProviderProtectedMessageRouter() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.weibo.api.motan.registry.zookeeper;

public enum ZkNodeType {
AVAILABLE_SERVER,
UNAVAILABLE_SERVER,
CLIENT
AVAILABLE_SERVER("server"),
UNAVAILABLE_SERVER("unavailableServer"),
CLIENT("client");

private String value;

private ZkNodeType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.weibo.api.motan.registry.zookeeper;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.exception.MotanFrameworkException;
import com.weibo.api.motan.rpc.URL;

public class ZkUtils {
Expand All @@ -19,17 +18,7 @@ public static String toCommandPath(URL url) {
}

public static String toNodeTypePath(URL url, ZkNodeType nodeType) {
String type;
if (nodeType == ZkNodeType.AVAILABLE_SERVER) {
type = "server";
} else if (nodeType == ZkNodeType.UNAVAILABLE_SERVER) {
type = "unavailableServer";
} else if (nodeType == ZkNodeType.CLIENT) {
type = "client";
} else {
throw new MotanFrameworkException(String.format("Failed to get nodeTypePath, url: %s type: %s", url, nodeType.toString()));
}
return toServicePath(url) + MotanConstants.PATH_SEPARATOR + type;
return toServicePath(url) + MotanConstants.PATH_SEPARATOR + nodeType.getValue();
}

public static String toNodePath(URL url, ZkNodeType nodeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,23 @@

package com.weibo.api.motan.config.springsupport;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.config.*;
import com.weibo.api.motan.exception.MotanErrorMsgConstant;
import com.weibo.api.motan.exception.MotanFrameworkException;
import com.weibo.api.motan.util.CollectionUtil;
import com.weibo.api.motan.util.MotanFrameworkUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.config.BasicServiceInterfaceConfig;
import com.weibo.api.motan.config.ConfigUtil;
import com.weibo.api.motan.config.ProtocolConfig;
import com.weibo.api.motan.config.RegistryConfig;
import com.weibo.api.motan.config.ServiceConfig;
import com.weibo.api.motan.exception.MotanErrorMsgConstant;
import com.weibo.api.motan.exception.MotanFrameworkException;
import com.weibo.api.motan.util.CollectionUtil;
import com.weibo.api.motan.util.MotanFrameworkUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class ServiceConfigBean<T> extends ServiceConfig<T>
implements
Expand Down Expand Up @@ -117,7 +107,7 @@ private void checkAndConfigBasicConfig() {
}
if (MotanNamespaceHandler.basicServiceConfigDefineNames.size() == 1) {
setBasicServiceConfig(biConfig);
} else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) {
} else if (biConfig.isDefault() != null && biConfig.isDefault()) {
setBasicServiceConfig(biConfig);
}
}
Expand Down

0 comments on commit c357080

Please sign in to comment.