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/11/29 06:05:21 UTC
[incubator-dubbo] branch dev-metadata updated: create separate
RouterChain for StaticDirectory
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/dev-metadata by this push:
new 4700f2c create separate RouterChain for StaticDirectory
4700f2c is described below
commit 4700f2c585d410c401cea9022ae95e55b8c2cc77
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Nov 29 14:05:08 2018 +0800
create separate RouterChain for StaticDirectory
---
.../src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java | 3 +++
.../org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java | 9 +++++++++
.../java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java | 3 ++-
.../dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java | 2 +-
.../org/apache/dubbo/registry/integration/RegistryDirectory.java | 4 +++-
5 files changed, 18 insertions(+), 3 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 7b13b9e..2848904 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
@@ -164,6 +164,9 @@ public class RouterChain<T> {
public List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) {
List<Invoker<T>> finalInvokers = invokers;
+ if (treeCache.getTree() != null) {
+ finalInvokers = treeCache.getInvokers(treeCache.getTree(), url, invocation);
+ }
for (Router router : routers) {
if (router.isRuntime()) {
finalInvokers = router.route(invokers, url, invocation);
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 154fafe..07b6419 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
@@ -19,12 +19,14 @@ package org.apache.dubbo.rpc.cluster.directory;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.RouterChain;
import java.util.List;
+import java.util.Map;
/**
* StaticDirectory
@@ -86,6 +88,13 @@ public class StaticDirectory<T> extends AbstractDirectory<T> {
invokers.clear();
}
+ public void buildRouterChain(Map<String, List<Invoker<T>>> methodGroupInvokers, DynamicConfiguration dynamicConfiguration) {
+ ;
+ RouterChain<T> routerChain = RouterChain.buildChain(dynamicConfiguration, getUrl());
+ routerChain.notifyFullInvokers(methodGroupInvokers, getUrl());
+ this.setRouterChain(routerChain);
+ }
+
@Override
protected List<Invoker<T>> doList(Invocation invocation) throws RpcException {
List<Invoker<T>> finalInvokers = invokers;
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java
index 188e0a1..da5e04d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java
@@ -80,8 +80,9 @@ public class ClusterUtils {
// All providers come to here have been filtered by group, which means only those providers that have the exact same group value with the consumer could come to here.
// So, generally, we don't need to care about the group value here.
// But when comes to group merger, there is an exception, the consumer group may be '*' while the provider group can be empty or any other values.
- localMap.remove(Constants.GROUP_KEY);
+ String remoteGroup = map.get(Constants.GROUP_KEY);
map.putAll(localMap);
+ map.put(Constants.GROUP_KEY, remoteGroup);
}
if (remoteMap != null && remoteMap.size() > 0) {
// Use version passed from provider side
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java
index dfd8156..1d5d42b 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java
@@ -44,7 +44,7 @@ public class RegistryAwareClusterInvoker<T> extends AbstractClusterInvoker<T> {
public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
// First, pick the invoker (XXXClusterInvoker) that comes from the local registry, distinguish by a 'default' key.
for (Invoker<T> invoker : invokers) {
- if (invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + Constants.DEFAULT_KEY, false)) {
+ if (invoker.isAvailable() && invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + Constants.DEFAULT_KEY, false)) {
return invoker.invoke(invocation);
}
}
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 ac29f28..bdf7a54 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
@@ -378,7 +378,9 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
List<Invoker<T>> groupInvokers = new ArrayList<Invoker<T>>();
for (List<Invoker<T>> groupList : groupMap.values()) {
StaticDirectory<T> staticDirectory = new StaticDirectory<>(groupList);
- staticDirectory.setRouterChain(routerChain);
+ Map<String, List<Invoker<T>>> methodGroupInvokers = new HashMap<>();
+ methodGroupInvokers.put(method, groupInvokers);
+ staticDirectory.buildRouterChain(methodGroupInvokers, dynamicConfiguration);
groupInvokers.add(cluster.join(staticDirectory));
}
result.put(method, groupInvokers);