From bb7932db07abb591621a9dee435ed10106e223b3 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Thu, 3 Jan 2019 13:07:03 +0800 Subject: [PATCH 1/3] code optimization --- .../cluster/directory/StaticDirectory.java | 4 +- .../rpc/cluster/router/AbstractRouter.java | 1 + .../apache/dubbo/common/logger/Logger.java | 40 +++++++++---------- .../apache/dubbo/common/utils/NetUtils.java | 29 +++++++------- .../apache/dubbo/config/AbstractConfig.java | 8 ++-- .../apache/dubbo/config/ReferenceConfig.java | 4 +- .../apache/dubbo/config/ServiceConfig.java | 6 +-- .../definition/model/MethodDefinition.java | 8 +++- .../definition/model/ServiceDefinition.java | 8 +++- .../definition/model/TypeDefinition.java | 8 +++- .../support/AbstractMetadataReport.java | 3 ++ .../remoting/transport/AbstractServer.java | 2 +- .../remoting/transport/mina/MinaServer.java | 2 +- .../support/AbstractZookeeperClient.java | 2 + .../rpc/protocol/injvm/InjvmInvoker.java | 3 +- 15 files changed, 74 insertions(+), 54 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index e868bd792c1..160543867cd 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -29,7 +29,6 @@ /** * StaticDirectory - * */ public class StaticDirectory extends AbstractDirectory { private static final Logger logger = LoggerFactory.getLogger(StaticDirectory.class); @@ -50,8 +49,9 @@ public StaticDirectory(URL url, List> invokers) { public StaticDirectory(URL url, List> invokers, RouterChain routerChain) { super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain); - if (invokers == null || invokers.isEmpty()) + if (invokers == null || invokers.isEmpty()) { throw new IllegalArgumentException("invokers == null"); + } this.invokers = invokers; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java index da4bd7c37eb..411c213eb29 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java @@ -70,6 +70,7 @@ public int compareTo(Router o) { return (this.getPriority() >= o.getPriority()) ? 1 : -1; } + @Override public int getPriority() { return priority; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java index 3b78d04542c..c505326d0c3 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java @@ -28,14 +28,14 @@ public interface Logger { * * @param msg log this message */ - public void trace(String msg); + void trace(String msg); /** * Logs an error with trace log level. * * @param e log this cause */ - public void trace(Throwable e); + void trace(Throwable e); /** * Logs an error with trace log level. @@ -43,21 +43,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void trace(String msg, Throwable e); + void trace(String msg, Throwable e); /** * Logs a message with debug log level. * * @param msg log this message */ - public void debug(String msg); + void debug(String msg); /** * Logs an error with debug log level. * * @param e log this cause */ - public void debug(Throwable e); + void debug(Throwable e); /** * Logs an error with debug log level. @@ -65,21 +65,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void debug(String msg, Throwable e); + void debug(String msg, Throwable e); /** * Logs a message with info log level. * * @param msg log this message */ - public void info(String msg); + void info(String msg); /** * Logs an error with info log level. * * @param e log this cause */ - public void info(Throwable e); + void info(Throwable e); /** * Logs an error with info log level. @@ -87,21 +87,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void info(String msg, Throwable e); + void info(String msg, Throwable e); /** * Logs a message with warn log level. * * @param msg log this message */ - public void warn(String msg); + void warn(String msg); /** * Logs a message with warn log level. * * @param e log this message */ - public void warn(Throwable e); + void warn(Throwable e); /** * Logs a message with warn log level. @@ -109,21 +109,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void warn(String msg, Throwable e); + void warn(String msg, Throwable e); /** * Logs a message with error log level. * * @param msg log this message */ - public void error(String msg); + void error(String msg); /** * Logs an error with error log level. * * @param e log this cause */ - public void error(Throwable e); + void error(Throwable e); /** * Logs an error with error log level. @@ -131,41 +131,41 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void error(String msg, Throwable e); + void error(String msg, Throwable e); /** * Is trace logging currently enabled? * * @return true if trace is enabled */ - public boolean isTraceEnabled(); + boolean isTraceEnabled(); /** * Is debug logging currently enabled? * * @return true if debug is enabled */ - public boolean isDebugEnabled(); + boolean isDebugEnabled(); /** * Is info logging currently enabled? * * @return true if info is enabled */ - public boolean isInfoEnabled(); + boolean isInfoEnabled(); /** * Is warn logging currently enabled? * * @return true if warn is enabled */ - public boolean isWarnEnabled(); + boolean isWarnEnabled(); /** * Is error logging currently enabled? * * @return true if error is enabled */ - public boolean isErrorEnabled(); + boolean isErrorEnabled(); } \ No newline at end of file diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index 29d79a30f0f..78b01b50354 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -37,8 +38,6 @@ */ public class NetUtils { - public static final String LOCALHOST = "127.0.0.1"; - public static final String ANYHOST = "0.0.0.0"; private static final Logger logger = LoggerFactory.getLogger(NetUtils.class); private static final int RND_PORT_START = 30000; @@ -109,18 +108,18 @@ public static boolean isValidAddress(String address) { public static boolean isLocalHost(String host) { return host != null && (LOCAL_IP_PATTERN.matcher(host).matches() - || host.equalsIgnoreCase("localhost")); + || host.equalsIgnoreCase(Constants.LOCALHOST_KEY)); } public static boolean isAnyHost(String host) { - return "0.0.0.0".equals(host); + return Constants.ANYHOST_VALUE.equals(host); } public static boolean isInvalidLocalHost(String host) { return host == null || host.length() == 0 - || host.equalsIgnoreCase("localhost") - || host.equals("0.0.0.0") + || host.equalsIgnoreCase(Constants.LOCALHOST_KEY) + || host.equals(Constants.ANYHOST_VALUE) || (LOCAL_IP_PATTERN.matcher(host).matches()); } @@ -139,13 +138,14 @@ static boolean isValidAddress(InetAddress address) { } String name = address.getHostAddress(); return (name != null - && !ANYHOST.equals(name) - && !LOCALHOST.equals(name) + && !Constants.ANYHOST_VALUE.equals(name) + && !Constants.LOCALHOST_VALUE.equals(name) && IP_PATTERN.matcher(name).matches()); } /** * Check if an ipv6 address is reachable. + * * @param address the given address * @return true if it is reachable */ @@ -166,12 +166,13 @@ static boolean isValidV6Address(Inet6Address address) { * normalize the ipv6 Address, convert scope name to scope id. * e.g. * convert - * fe80:0:0:0:894:aeec:f37d:23e1%en0 + * fe80:0:0:0:894:aeec:f37d:23e1%en0 * to - * fe80:0:0:0:894:aeec:f37d:23e1%5 - * + * fe80:0:0:0:894:aeec:f37d:23e1%5 + *

* The %5 after ipv6 address is called scope id. * see java doc of {@link Inet6Address} for more details. + * * @param address the input address * @return the normalized address, with scope id converted to int */ @@ -191,7 +192,7 @@ static InetAddress normalizeV6Address(Inet6Address address) { public static String getLocalHost() { InetAddress address = getLocalAddress(); - return address == null ? LOCALHOST : address.getHostAddress(); + return address == null ? Constants.LOCALHOST_VALUE : address.getHostAddress(); } public static String filterLocalHost(String host) { @@ -236,7 +237,7 @@ private static InetAddress getLocalAddress0() { localAddress = InetAddress.getLocalHost(); if (localAddress instanceof Inet6Address) { Inet6Address address = (Inet6Address) localAddress; - if (isValidV6Address(address)){ + if (isValidV6Address(address)) { return normalizeV6Address(address); } } else if (isValidAddress(localAddress)) { @@ -259,7 +260,7 @@ private static InetAddress getLocalAddress0() { InetAddress address = addresses.nextElement(); if (address instanceof Inet6Address) { Inet6Address v6Address = (Inet6Address) address; - if (isValidV6Address(v6Address)){ + if (isValidV6Address(v6Address)) { return normalizeV6Address(v6Address); } } else if (isValidAddress(address)) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 6394097202f..06b360ddee4 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -318,9 +318,9 @@ protected static void checkExtension(Class type, String property, String valu * Check whether there is a Extension who's name (property) is value (special treatment is * required) * - * @param type The Extension type + * @param type The Extension type * @param property The extension key - * @param value The Extension name + * @param value The Extension name */ protected static void checkMultiExtension(Class type, String property, String value) { checkMultiName(property, value); @@ -500,7 +500,7 @@ public Map getMetaData() { try { String name = method.getName(); if ((name.startsWith("get") || name.startsWith("is")) - && !name.equals("get") + && !"get".equals(name) && !"getClass".equals(name) && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0 @@ -565,7 +565,7 @@ public void refresh() { config.addProperties(getMetaData()); if (Environment.getInstance().isConfigCenterFirst()) { // The sequence would be: SystemConfiguration -> ExternalConfiguration -> AppExternalConfiguration -> AbstractConfig -> PropertiesConfiguration - compositeConfiguration.addConfiguration(3,config); + compositeConfiguration.addConfiguration(3, config); } else { // The sequence would be: SystemConfiguration -> AbstractConfig -> ExternalConfiguration -> AppExternalConfiguration -> PropertiesConfiguration compositeConfiguration.addConfiguration(1, config); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index ea75c3d50f3..3110d762ecc 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -72,7 +72,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { * *

  • when the url is dubbo://224.5.6.7:1234/org.apache.dubbo.config.api.DemoService?application=dubbo-sample, then * the protocol is DubboProtocol
  • - * + *

    * Actually,when the {@link ExtensionLoader} init the {@link Protocol} instants,it will automatically wraps two * layers, and eventually will get a ProtocolFilterWrapper or ProtocolListenerWrapper */ @@ -327,7 +327,7 @@ private T createProxy(Map map) { } if (isJvmRefer) { - URL url = new URL(Constants.LOCAL_PROTOCOL, NetUtils.LOCALHOST, 0, interfaceClass.getName()).addParameters(map); + URL url = new URL(Constants.LOCAL_PROTOCOL, Constants.LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map); invoker = refprotocol.refer(interfaceClass, url); if (logger.isInfoEnabled()) { logger.info("Using injvm service " + interfaceClass.getName()); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 0309ff039b2..e1e3d0c969f 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -57,7 +57,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static org.apache.dubbo.common.utils.NetUtils.LOCALHOST; +import static org.apache.dubbo.common.Constants.LOCALHOST_VALUE; import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort; import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; @@ -82,7 +82,7 @@ public class ServiceConfig extends AbstractServiceConfig { * *

  • when the url is dubbo://224.5.6.7:1234/org.apache.dubbo.config.api.DemoService?application=dubbo-sample, then * the protocol is DubboProtocol
  • - * + *

    * Actually,when the {@link ExtensionLoader} init the {@link Protocol} instants,it will automatically wraps two * layers, and eventually will get a ProtocolFilterWrapper or ProtocolListenerWrapper */ @@ -583,7 +583,7 @@ private void exportLocal(URL url) { if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { URL local = URL.valueOf(url.toFullString()) .setProtocol(Constants.LOCAL_PROTOCOL) - .setHost(LOCALHOST) + .setHost(LOCALHOST_VALUE) .setPort(0); Exporter exporter = protocol.export( proxyFactory.getInvoker(ref, (Class) interfaceClass, local)); diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java index c1e154840d6..3746ab5b9bd 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java @@ -74,8 +74,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MethodDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof MethodDefinition)) { + return false; + } MethodDefinition that = (MethodDefinition) o; return Objects.equals(getName(), that.getName()) && Arrays.equals(getParameterTypes(), that.getParameterTypes()) && diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java index f94e4d5704c..78d3bcb6f66 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java @@ -80,8 +80,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ServiceDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof ServiceDefinition)) { + return false; + } ServiceDefinition that = (ServiceDefinition) o; return Objects.equals(getCanonicalName(), that.getCanonicalName()) && Objects.equals(getCodeSource(), that.getCodeSource()) && diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java index f4cc145f8d6..7ca5bd894aa 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java @@ -106,8 +106,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TypeDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof TypeDefinition)) { + return false; + } TypeDefinition that = (TypeDefinition) o; return Objects.equals(getId(), that.getId()) && Objects.equals(getType(), that.getType()) && diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java index 9aab901f5d1..09e6e0bb318 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java @@ -52,6 +52,7 @@ import java.util.concurrent.atomic.AtomicLong; /** + * */ public abstract class AbstractMetadataReport implements MetadataReport { @@ -229,6 +230,7 @@ public void run() { } } + @Override public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition) { if (syncReport) { storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition); @@ -261,6 +263,7 @@ private void storeProviderMetadataTask(MetadataIdentifier providerMetadataIdenti } } + @Override public void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map serviceParameterMap) { if (syncReport) { storeConsumerMetadataTask(consumerMetadataIdentifier, serviceParameterMap); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java index c95183835b9..2020fee79fb 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java @@ -54,7 +54,7 @@ public AbstractServer(URL url, ChannelHandler handler) throws RemotingException String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost()); int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort()); if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) { - bindIp = NetUtils.ANYHOST; + bindIp = Constants.ANYHOST_VALUE; } bindAddress = new InetSocketAddress(bindIp, bindPort); this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS); diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java index 80e336d7e82..540213b4443 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java @@ -60,7 +60,7 @@ protected void doOpen() throws Throwable { Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config - SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig(); + SocketAcceptorConfig cfg = acceptor.getDefaultConfig(); cfg.setThreadModel(ThreadModel.MANUAL); // set codec. acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java index 852c974111e..e90f7fb9c71 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java @@ -127,6 +127,7 @@ public void close() { } } + @Override public void create(String path, String content, boolean ephemeral) { if (checkExists(path)) { delete(path); @@ -142,6 +143,7 @@ public void create(String path, String content, boolean ephemeral) { } } + @Override public String getContent(String path) { if (!checkExists(path)) { return null; diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 591022ecde4..54144e02093 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.rpc.protocol.injvm; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Exporter; @@ -58,7 +59,7 @@ public Result doInvoke(Invocation invocation) throws Throwable { if (exporter == null) { throw new RpcException("Service [" + key + "] not found."); } - RpcContext.getContext().setRemoteAddress(NetUtils.LOCALHOST, 0); + RpcContext.getContext().setRemoteAddress(Constants.LOCALHOST_VALUE, 0); return exporter.getInvoker().invoke(invocation); } } From e4ef2c7ab1668603f8de9d0f91625cc7898899ff Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Thu, 3 Jan 2019 13:38:22 +0800 Subject: [PATCH 2/3] useless import --- .../java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 54144e02093..37d23d5bdf7 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -18,7 +18,6 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Result; From 802ad54454f5342d03af6283aba3f293354046a8 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Thu, 3 Jan 2019 16:13:53 +0800 Subject: [PATCH 3/3] optimization --- .../apache/dubbo/common/utils/NetUtils.java | 4 +-- .../apache/dubbo/config/AbstractConfig.java | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index 78b01b50354..fafe1518f91 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -138,9 +138,9 @@ static boolean isValidAddress(InetAddress address) { } String name = address.getHostAddress(); return (name != null + && IP_PATTERN.matcher(name).matches() && !Constants.ANYHOST_VALUE.equals(name) - && !Constants.LOCALHOST_VALUE.equals(name) - && IP_PATTERN.matcher(name).matches()); + && !Constants.LOCALHOST_VALUE.equals(name)); } /** diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index c9c50f0e21c..5921abc3d35 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -485,12 +485,7 @@ public Map getMetaData() { for (Method method : methods) { try { String name = method.getName(); - if ((name.startsWith("get") || name.startsWith("is")) - && !"get".equals(name) - && !"getClass".equals(name) - && Modifier.isPublic(method.getModifiers()) - && method.getParameterTypes().length == 0 - && ClassHelper.isPrimitive(method.getReturnType())) { + if (isMetaMethod(method)) { String prop = calculateAttributeFromGetter(name); String key; Parameter parameter = method.getAnnotation(Parameter.class); @@ -620,4 +615,27 @@ public boolean isValid() { return true; } + private boolean isMetaMethod(Method method) { + String name = method.getName(); + if (!(name.startsWith("get") || name.startsWith("is"))) { + return false; + } + if ("get".equals(name)) { + return false; + } + if ("getClass".equals(name)) { + return false; + } + if (!Modifier.isPublic(method.getModifiers())) { + return false; + } + if (method.getParameterTypes().length != 0) { + return false; + } + if (!ClassHelper.isPrimitive(method.getReturnType())) { + return false; + } + return true; + } + }