Skip to content

Commit

Permalink
Fix some code according to the inspection results of 'Alibaba Coding…
Browse files Browse the repository at this point in the history
… Guidelines'. (sofastack#24)
  • Loading branch information
ujjboy authored Apr 18, 2018
1 parent a289c7b commit 3ea59d6
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static RouterChain buildConsumerChain(ConsumerBootstrap consumerBootstrap
}
}
// 解析自动加载的router
if (!excludes.contains("*") && !excludes.contains("default")) { // 配了-*和-default表示不加载内置
if (!excludes.contains(StringUtils.ALL) && !excludes.contains(StringUtils.DEFAULT)) { // 配了-*和-default表示不加载内置
for (Map.Entry<String, ExtensionClass<Router>> entry : CONSUMER_AUTO_ACTIVES.entrySet()) {
if (!excludes.contains(entry.getKey())) {
extensionRouters.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ public static List<InetSocketAddress> getIpListByRegistry(String registryIp) {
*/
public static boolean isMatchIPByPattern(String whiteList, String localIP) {
if (StringUtils.isNotBlank(whiteList)) {
if ("*".equals(whiteList)) {
if (StringUtils.ALL.equals(whiteList)) {
return true;
}
for (String ips : whiteList.replace(',', ';').split(";", -1)) {
try {
if (ips.contains("*")) { // 带通配符
if (ips.contains(StringUtils.ALL)) { // 带通配符
String regex = ips.trim().replace(".", "\\.").replace("*", ".*");
Pattern pattern = Pattern.compile(regex);
if (pattern.matcher(localIP).find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public synchronized Map<String, Object> getConfigValueCache(boolean rebuild) {
if (configValueCache != null && !rebuild) {
return configValueCache;
}
Map<String, Object> context = new HashMap<String, Object>();
Map<String, Object> context = new HashMap<String, Object>(32);
Map<String, String> providerParams = getParameters();
if (providerParams != null) {
context.putAll(providerParams); // 复制接口的自定义参数
Expand Down Expand Up @@ -892,7 +892,7 @@ public boolean updateAttribute(String property, String newValueStr, boolean over
}
if (changed && overwrite) {
BeanUtils.setProperty(methodConfig, methodProperty, propertyClazz, newValue);// 覆盖属性
if (LOGGER.isWarnEnabled()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Property \"" + methodName + "." + methodProperty + "\" changed from {} to {}",
oldValue, newValueStr);
}
Expand All @@ -913,7 +913,7 @@ public boolean updateAttribute(String property, String newValueStr, boolean over
}
if (changed && overwrite) {
BeanUtils.setProperty(this, property, propertyClazz, newValue);// 覆盖属性
if (LOGGER.isWarnEnabled()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Property \"" + property + "\" changed from {} to {}", oldValue, newValueStr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected void readLine(URL url, String line) throws Throwable {
}
}
// 不可以是default和*
if ("default".equals(alias) || "*".equals(alias)) {
if (StringUtils.DEFAULT.equals(alias) || StringUtils.ALL.equals(alias)) {
throw new IllegalArgumentException("Error when load extension of extensible " + interfaceName +
" from file:" + url + ", alias of @Extension must not \"default\" and \"*\" at " + className + ".");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static FilterChain buildProviderChain(ProviderConfig<?> providerConfig, F
}
}
// 解析自动加载的过滤器
if (!excludes.contains("*") && !excludes.contains("default")) { // 配了-*和-default表示不加载内置
if (!excludes.contains(StringUtils.ALL) && !excludes.contains(StringUtils.DEFAULT)) { // 配了-*和-default表示不加载内置
for (Map.Entry<String, ExtensionClass<Filter>> entry : PROVIDER_AUTO_ACTIVES.entrySet()) {
if (!excludes.contains(entry.getKey())) {
extensionFilters.add(entry.getValue());
Expand Down Expand Up @@ -234,7 +234,7 @@ public static FilterChain buildConsumerChain(ConsumerConfig<?> consumerConfig, F
}
}
// 解析自动加载的过滤器
if (!excludes.contains("*") && !excludes.contains("default")) { // 配了-*和-default表示不加载内置
if (!excludes.contains(StringUtils.ALL) && !excludes.contains(StringUtils.DEFAULT)) { // 配了-*和-default表示不加载内置
for (Map.Entry<String, ExtensionClass<Filter>> entry : CONSUMER_AUTO_ACTIVES.entrySet()) {
if (!excludes.contains(entry.getKey())) {
extensionFilters.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class StringUtils {
/**
* The empty String {@code ""}.
*
* @since 2.0
* @since 5.0.0
*/
public static final String EMPTY = "";

Expand All @@ -39,6 +39,20 @@ public class StringUtils {
*/
public static final String CONTEXT_SEP = "/";

/**
* The string {@code "*"}.
*
* @since 5.3.1
*/
public static final String ALL = "*";

/**
* The string {@code "default"}.
*
* @since 5.3.1
*/
public static final String DEFAULT = "default";

/**
* 空数组
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public static void main(String[] args) {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("dubbo-server");

ServerConfig serverConfig = new ServerConfig()
// .setHost("0.0.0.0")
// .setPort(22222)
.setProtocol("dubbo")
.setHost("127.0.0.1")
.setPort(20080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public synchronized void attrUpdated(Map newValueMap) {
*/
protected boolean inList(String includeMethods, String excludeMethods, String methodName) {
//判断是否在白名单中
if (includeMethods != null && !"*".equals(includeMethods)) {
if (includeMethods != null && !StringUtils.ALL.equals(includeMethods)) {
includeMethods = includeMethods + ",";
boolean inWhite = includeMethods.contains(methodName + ",");
if (!inWhite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public void start() {
try {
httpServer = buildServer();
httpServer.start();
LOGGER.info("Start the http rest server at port {}", serverConfig.getPort());
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Start the http rest server at port {}", serverConfig.getPort());
}
} catch (Exception e) {
throw new SofaRpcRuntimeException(
"Failed to start jetty server at port " + serverConfig.getPort() + ", cause: " + e.getMessage(), e);
Expand All @@ -167,7 +169,9 @@ public void stop() {
}
try {
// 关闭端口,不关闭线程池
LOGGER.info("Stop the http rest server at port {}", serverConfig.getPort());
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Stop the http rest server at port {}", serverConfig.getPort());
}
httpServer.stop();
httpServer = null;
} catch (Exception e) {
Expand All @@ -182,8 +186,10 @@ public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
start();
}
// 在httpserver中注册此jaxrs服务
LOGGER.info("Register jaxrs service to base url http://" + serverConfig.getHost() + ":"
+ serverConfig.getPort() + serverConfig.getContextPath());
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Register jaxrs service to base url http://" + serverConfig.getHost() + ":"
+ serverConfig.getPort() + serverConfig.getContextPath());
}
try {
httpServer.getDeployment().getRegistry()
.addResourceFactory(new SofaResourceFactory(providerConfig), serverConfig.getContextPath());
Expand All @@ -199,8 +205,10 @@ public void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNo
if (!isStarted()) {
return;
}
LOGGER.info("Unregister jaxrs service to port {} and base path is {}", serverConfig.getPort(),
serverConfig.getContextPath());
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Unregister jaxrs service to port {} and base path is {}", serverConfig.getPort(),
serverConfig.getContextPath());
}
try {
httpServer.getDeployment().getRegistry()
.removeRegistrations(providerConfig.getRef().getClass(), serverConfig.getContextPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alipay.sofa.rpc.common.SystemInfo;
import com.alipay.sofa.rpc.common.struct.NamedThreadFactory;
import com.alipay.sofa.rpc.common.utils.StringUtils;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
Expand Down Expand Up @@ -182,7 +183,7 @@ public void setDeployment(ResteasyDeployment deployment) {
@Override
public void setRootResourcePath(String rootResourcePath) {
root = rootResourcePath;
if (root != null && "/".equals(root)) {
if (root != null && StringUtils.CONTEXT_SEP.equals(root)) {
root = "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public void start()
throw new RuntimeException("Unable to instantiate context object " + entry.getKey(), e);
}
Object obj = createFromInjectorFactory(entry.getValue(), providerFactory);
LOGGER.debug("Creating context object <" + entry.getKey() + " : " + entry.getValue() + ">");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Creating context object <" + entry.getKey() + " : " + entry.getValue() + ">");
}
defaultContextObjects.put(key, obj);
dispatcher.getDefaultContextObjects().put(key, obj);
contextDataMap.put(key, obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected Object buildProxy(ClientTransportConfig transportConfig) throws SofaRp

ProviderInfo provider = transportConfig.getProviderInfo();
String url = "http://" + provider.getHost() + ":" + provider.getPort()
+ "/" + StringUtils.trimToEmpty(provider.getPath());
+ StringUtils.CONTEXT_SEP + StringUtils.trimToEmpty(provider.getPath());
ResteasyWebTarget target = client.target(url);
return target.proxy(ClassUtils.forName(transportConfig.getConsumerConfig().getInterfaceId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public ValueInjector createParameterExtractor(Class injectTargetClass, Accessibl
Type genericType,
Annotation[] annotations, boolean useDefault,
ResteasyProviderFactory providerFactory) {
CustomerAnnotation customerAnnotation;
if ((customerAnnotation = findAnnotation(annotations, CustomerAnnotation.class)) != null) {
if (findAnnotation(annotations, CustomerAnnotation.class) != null) {
return new CustomerInject();
}

Expand Down

0 comments on commit 3ea59d6

Please sign in to comment.