Skip to content

Commit a868472

Browse files
authored
Merge pull request #9 from apache/master
Master sync
2 parents 5b67c0f + 09cbf8f commit a868472

File tree

37 files changed

+374
-244
lines changed

37 files changed

+374
-244
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.apache.dubbo.common.URL;
2121
import org.apache.dubbo.common.logger.Logger;
2222
import org.apache.dubbo.common.logger.LoggerFactory;
23-
import org.apache.dubbo.common.utils.Assert;
2423
import org.apache.dubbo.common.utils.CollectionUtils;
24+
import org.apache.dubbo.common.utils.StringUtils;
2525
import org.apache.dubbo.configcenter.ConfigChangeEvent;
2626
import org.apache.dubbo.configcenter.ConfigChangeType;
2727
import org.apache.dubbo.configcenter.ConfigurationListener;
@@ -125,12 +125,14 @@ private void generateConditions(ConditionRouterRule rule, List<ConditionRouter>
125125
}
126126

127127
private synchronized void init(String ruleKey) {
128-
Assert.notEmptyString(ruleKey, "router rule's key cannot be null");
129-
String router = ruleKey + Constants.ROUTERS_SUFFIX;
130-
configuration.addListener(router, this);
131-
String rule = configuration.getConfig(router);
128+
if (StringUtils.isEmpty(ruleKey)) {
129+
return;
130+
}
131+
String routerKey = ruleKey + Constants.ROUTERS_SUFFIX;
132+
configuration.addListener(routerKey, this);
133+
String rule = configuration.getConfig(routerKey);
132134
if (rule != null) {
133-
this.process(new ConfigChangeEvent(router, rule));
135+
this.process(new ConfigChangeEvent(routerKey, rule));
134136
}
135137
}
136138
}

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ public Router getRouter(URL url) {
5353
}
5454
String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath())));
5555

56+
// FIXME: this code looks useless
5657
boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false);
57-
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameter(Constants.RUNTIME_KEY, runtime).addParameterAndEncoded(Constants.RULE_KEY, rule);
58+
URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type)
59+
.addParameter(Constants.RUNTIME_KEY, runtime)
60+
.addParameterAndEncoded(Constants.RULE_KEY, rule);
5861

5962
return routerFactory.getRouter(script);
6063
} catch (IOException e) {

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ScriptRouter extends AbstractRouter {
4545
public static final String NAME = "SCRIPT_ROUTER";
4646
private static final Logger logger = LoggerFactory.getLogger(ScriptRouter.class);
4747

48-
private static final Map<String, ScriptEngine> engines = new ConcurrentHashMap<String, ScriptEngine>();
48+
private static final Map<String, ScriptEngine> engines = new ConcurrentHashMap<>();
4949

5050
private final ScriptEngine engine;
5151

@@ -62,13 +62,13 @@ public ScriptRouter(URL url) {
6262
type = Constants.DEFAULT_SCRIPT_TYPE_KEY;
6363
}
6464
if (rule == null || rule.length() == 0) {
65-
throw new IllegalStateException(new IllegalStateException("route rule can not be empty. rule:" + rule));
65+
throw new IllegalStateException("route rule can not be empty. rule:" + rule);
6666
}
6767
ScriptEngine engine = engines.get(type);
6868
if (engine == null) {
6969
engine = new ScriptEngineManager().getEngineByName(type);
7070
if (engine == null) {
71-
throw new IllegalStateException(new IllegalStateException("Unsupported route rule type: " + type + ", rule: " + rule));
71+
throw new IllegalStateException("unsupported route rule type: " + type + ", rule: " + rule);
7272
}
7373
engines.put(type, engine);
7474
}
@@ -85,7 +85,7 @@ public URL getUrl() {
8585
@SuppressWarnings("unchecked")
8686
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
8787
try {
88-
List<Invoker<T>> invokersCopy = new ArrayList<Invoker<T>>(invokers);
88+
List<Invoker<T>> invokersCopy = new ArrayList<>(invokers);
8989
Compilable compilable = (Compilable) engine;
9090
Bindings bindings = engine.createBindings();
9191
bindings.put("invokers", invokersCopy);
@@ -105,8 +105,8 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
105105
}
106106
return invokersCopy;
107107
} catch (ScriptException e) {
108-
//fail then ignore rule .invokers.
109-
logger.error("route error , rule has been ignored. rule: " + rule + ", method:" + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
108+
logger.error("route error, rule has been ignored. rule: " + rule + ", method:" +
109+
invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
110110
return invokers;
111111
}
112112
}

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import static org.apache.dubbo.common.Constants.TAG_KEY;
4343

4444
/**
45-
*
45+
* TagRouter
4646
*/
4747
public class TagRouter extends AbstractRouter implements Comparable<Router>, ConfigurationListener {
4848
public static final String NAME = "TAG_ROUTER";
@@ -117,10 +117,9 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
117117
}
118118
// FAILOVER: return all Providers without any tags.
119119
else {
120-
List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), tagRouterRule
121-
.getAddresses()));
122-
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl()
123-
.getParameter(TAG_KEY)));
120+
List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(),
121+
tagRouterRule.getAddresses()));
122+
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY)));
124123
}
125124
} else {
126125
// List<String> addresses = tagRouterRule.filter(providerApp);
@@ -137,10 +136,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
137136
}
138137
return filterInvoker(result, invoker -> {
139138
String localTag = invoker.getUrl().getParameter(TAG_KEY);
140-
if (StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag)) {
141-
return true;
142-
}
143-
return false;
139+
return StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag);
144140
});
145141
}
146142
}

dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.dubbo.config.spring.ReferenceBean;
2020

2121
import com.alibaba.dubbo.config.annotation.Reference;
22+
2223
import org.apache.commons.logging.Log;
2324
import org.apache.commons.logging.LogFactory;
2425
import org.springframework.beans.BeanUtils;

dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.dubbo.config.spring.convert.converter.StringArrayToStringConverter;
2323

2424
import com.alibaba.dubbo.config.annotation.Reference;
25+
2526
import org.springframework.context.ApplicationContext;
2627
import org.springframework.core.convert.ConversionService;
2728
import org.springframework.core.convert.support.DefaultConversionService;

dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
2323

2424
import com.alibaba.dubbo.config.annotation.Service;
25+
2526
import org.springframework.beans.BeansException;
2627
import org.springframework.beans.MutablePropertyValues;
2728
import org.springframework.beans.factory.BeanClassLoaderAware;

dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
package org.apache.dubbo.cache;
1919

20+
import org.apache.dubbo.rpc.RpcInvocation;
21+
2022
import com.alibaba.dubbo.cache.Cache;
2123
import com.alibaba.dubbo.cache.CacheFactory;
2224
import com.alibaba.dubbo.common.URL;
2325
import com.alibaba.dubbo.rpc.Invocation;
2426
import com.alibaba.dubbo.rpc.Invoker;
2527

26-
import org.apache.dubbo.rpc.RpcInvocation;
2728
import org.junit.Assert;
2829
import org.junit.Test;
2930

dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.alibaba.dubbo.config.ApplicationConfig;
2222
import com.alibaba.dubbo.config.MonitorConfig;
2323
import com.alibaba.dubbo.config.RegistryConfig;
24+
2425
import org.junit.Test;
2526

2627
import java.util.Collections;

dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package org.apache.dubbo.config;
1919

20+
import com.alibaba.dubbo.config.ArgumentConfig;
21+
2022
import org.junit.Test;
2123

2224
import java.util.HashMap;
2325
import java.util.Map;
2426

25-
import com.alibaba.dubbo.config.ArgumentConfig;
26-
2727
import static org.hamcrest.Matchers.equalTo;
2828
import static org.hamcrest.Matchers.hasEntry;
2929
import static org.hamcrest.Matchers.is;

0 commit comments

Comments
 (0)