You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/12/27 07:41:13 UTC
[incubator-dubbo] branch master updated: Revert code to avoid NPE
in RPC wire after providers are cleared.
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new c18b1cf Revert code to avoid NPE in RPC wire after providers are cleared.
c18b1cf is described below
commit c18b1cfb465181b0a446eb37cb12e5a4eab1d617
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Dec 27 15:41:02 2018 +0800
Revert code to avoid NPE in RPC wire after providers are cleared.
---
.../org/apache/dubbo/rpc/cluster/RouterChain.java | 10 +++---
.../registry/integration/RegistryDirectory.java | 37 +---------------------
2 files changed, 5 insertions(+), 42 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
index 9681ea3..ca6e98f 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
@@ -79,12 +80,11 @@ public class RouterChain<T> {
* @param routers routers from 'router://' rules in 2.6.x or before.
*/
public void addRouters(List<Router> routers) {
- // FIXME will sort cause concurrent problem? since it's kind of a write operation.
List<Router> newRouters = new CopyOnWriteArrayList<>();
newRouters.addAll(builtinRouters);
newRouters.addAll(routers);
+ CollectionUtils.sort(routers);
this.routers = newRouters;
- this.sort();
}
private void sort() {
@@ -110,9 +110,7 @@ public class RouterChain<T> {
* Notify whenever addresses in registry change.
*/
public void setInvokers(List<Invoker<T>> invokers) {
- if (invokers != null) {
- this.invokers = invokers;
- routers.forEach(router -> router.notify(invokers));
- }
+ this.invokers = (invokers == null ? Collections.emptyList() : invokers);
+ routers.forEach(router -> router.notify(this.invokers));
}
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
index 34093da..e886d13 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
@@ -227,7 +227,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
.get(0)
.getProtocol())) {
this.forbidden = true; // Forbid to access
- this.invokers = null;
+ this.invokers = Collections.emptyList();
routerChain.setInvokers(this.invokers);
destroyAllInvokers(); // Close all invokers
} else {
@@ -295,41 +295,6 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
return mergedInvokers;
}
- /*private Map<String, List<Invoker<T>>> toMergeMethodInvokerMap(Map<String, List<Invoker<T>>> methodMap) {
- Map<String, List<Invoker<T>>> result = new HashMap<String, List<Invoker<T>>>();
- for (Map.Entry<String, List<Invoker<T>>> entry : methodMap.entrySet()) {
- String method = entry.getKey();
- List<Invoker<T>> invokers = entry.getValue();
- Map<String, List<Invoker<T>>> groupMap = new HashMap<String, List<Invoker<T>>>();
- for (Invoker<T> invoker : invokers) {
- String group = invoker.getUrl().getParameter(Constants.GROUP_KEY, "");
- List<Invoker<T>> groupInvokers = groupMap.get(group);
- if (groupInvokers == null) {
- groupInvokers = new ArrayList<Invoker<T>>();
- groupMap.put(group, groupInvokers);
- }
- groupInvokers.add(invoker);
- }
- if (groupMap.size() == 1) {
- result.put(method, groupMap.values().iterator().next());
- } else if (groupMap.size() > 1) {
- List<Invoker<T>> groupInvokers = new ArrayList<Invoker<T>>();
- for (List<Invoker<T>> groupList : groupMap.values()) {
- StaticDirectory<T> staticDirectory = new StaticDirectory<>(groupList);
- Map<String, List<Invoker<T>>> methodGroupInvokers = new HashMap<>();
- methodGroupInvokers.put(method, groupList);
- staticDirectory.buildRouterChain(methodGroupInvokers, dynamicConfiguration);
- groupInvokers.add(cluster.join(staticDirectory));
- }
- result.put(method, groupInvokers);
- } else {
- result.put(method, invokers);
- }
- }
- return result;
- }
-*/
-
/**
* @param urls
* @return null : no routers ,do nothing