You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/15 09:52:39 UTC
[dubbo] branch 3.0 updated: Optimize RouterChain code (#8044)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 4e73f0d Optimize RouterChain code (#8044)
4e73f0d is described below
commit 4e73f0d8a5cdd8702d7d8b9152639cb7f4555b10
Author: Xiong, Pin <pi...@foxmail.com>
AuthorDate: Tue Jun 15 04:52:27 2021 -0500
Optimize RouterChain code (#8044)
1. remove the wrong logger
2. extract constant
3. update access permission
---
.../main/java/org/apache/dubbo/rpc/cluster/Constants.java | 5 +++++
.../main/java/org/apache/dubbo/rpc/cluster/RouterChain.java | 12 +++++-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
index b9935fc..58ccd2d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
@@ -91,6 +91,11 @@ public interface Constants {
* key for router type, for e.g., "script"/"file", corresponding to ScriptRouterFactory.NAME, FileRouterFactory.NAME
*/
String ROUTER_KEY = "router";
+
+ /**
+ * The key for state router
+ */
+ String STATE_ROUTER_KEY="stateRouter";
/**
* The key name for reference URL in register center
*/
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 f231036..23ae701 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
@@ -27,7 +27,6 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.router.state.AddrCache;
import org.apache.dubbo.rpc.cluster.router.state.BitList;
import org.apache.dubbo.rpc.cluster.router.state.RouterCache;
@@ -45,6 +44,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY;
+import static org.apache.dubbo.rpc.cluster.Constants.STATE_ROUTER_KEY;
/**
* Router chain
@@ -69,7 +69,7 @@ public class RouterChain<T> {
protected URL url;
- protected AtomicReference<AddrCache<T>> cache = new AtomicReference<>();
+ private AtomicReference<AddrCache<T>> cache = new AtomicReference<>();
private final Semaphore loopPermit = new Semaphore(1);
private final Semaphore loopPermitNotify = new Semaphore(1);
@@ -78,8 +78,6 @@ public class RouterChain<T> {
private boolean firstBuildCache = true;
- private static final Logger logger = LoggerFactory.getLogger(StaticDirectory.class);
-
public static <T> RouterChain<T> buildChain(URL url) {
return new RouterChain<>(url);
}
@@ -97,7 +95,7 @@ public class RouterChain<T> {
List<StateRouterFactory> extensionStateRouterFactories = ExtensionLoader.getExtensionLoader(
StateRouterFactory.class)
- .getActivateExtension(url, "stateRouter");
+ .getActivateExtension(url, STATE_ROUTER_KEY);
List<StateRouter> stateRouters = extensionStateRouterFactories.stream()
.map(factory -> factory.getRouter(url, this))
@@ -118,7 +116,7 @@ public class RouterChain<T> {
this.sort();
}
- public void initWithStateRouters(List<StateRouter> builtinRouters) {
+ private void initWithStateRouters(List<StateRouter> builtinRouters) {
this.builtinStateRouters = builtinRouters;
this.stateRouters = new ArrayList<>(builtinRouters);
}
@@ -221,7 +219,7 @@ public class RouterChain<T> {
//file cache
routerCacheMap.put(stateRouter.getName(), routerCache);
} catch (Throwable t) {
- logger.error("Failed to pool router: " + stateRouter.getUrl() + ", cause: " + t.getMessage(), t);
+ LOGGER.error("Failed to pool router: " + stateRouter.getUrl() + ", cause: " + t.getMessage(), t);
return;
}
}