Skip to content

Commit ee573b5

Browse files
committed
#31348905
1 parent 9e47376 commit ee573b5

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public static <T> RouterChain<T> buildChain(URL url) {
8383
return new RouterChain<>(url);
8484
}
8585

86+
public RouterChain(List<Invoker<T>> invokers) {
87+
this.invokers = invokers;
88+
}
89+
8690
private RouterChain(URL url) {
8791
List<RouterFactory> extensionFactories = ExtensionLoader.getExtensionLoader(RouterFactory.class)
8892
.getActivateExtension(url, "router");
@@ -146,6 +150,14 @@ public void addRouters(List<Router> routers) {
146150
this.routers = newRouters;
147151
}
148152

153+
public void addStateRouters(List<StateRouter> stateRouters) {
154+
List<StateRouter> newStateRouters = new ArrayList<>();
155+
newStateRouters.addAll(builtinStateRouters);
156+
newStateRouters.addAll(stateRouters);
157+
CollectionUtils.sort(newStateRouters);
158+
this.stateRouters = newStateRouters;
159+
}
160+
149161
private void sort() {
150162
Collections.sort(routers);
151163
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.apache.dubbo.rpc.cluster.router;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.apache.dubbo.common.URL;
7+
import org.apache.dubbo.rpc.Invocation;
8+
import org.apache.dubbo.rpc.Invoker;
9+
import org.apache.dubbo.rpc.cluster.RouterChain;
10+
import org.apache.dubbo.rpc.cluster.router.state.StateRouter;
11+
import org.apache.dubbo.rpc.cluster.router.tag.TagDynamicStateRouter;
12+
13+
public class StateRouterTest {
14+
public static void main(String[] args) {
15+
List<Invoker> list = mockInvokers();
16+
17+
RouterChain chain = new RouterChain(list);
18+
List<StateRouter> routers = new ArrayList<>();
19+
routers.add(new TagDynamicStateRouter(null));
20+
chain.addStateRouters(routers);
21+
22+
URL url = mockURL();
23+
Invocation invocation = mockInvocation();
24+
long start = System.currentTimeMillis();
25+
chain.route(url, invocation);
26+
System.out.println("cost:" + (System.currentTimeMillis() - start));
27+
}
28+
29+
private static List<Invoker> mockInvokers() {
30+
List<Invoker> list = new ArrayList<>();
31+
32+
33+
34+
return list;
35+
}
36+
37+
private static URL mockURL() {
38+
39+
return null;
40+
}
41+
42+
private static Invocation mockInvocation() {
43+
44+
return null;
45+
}
46+
}

0 commit comments

Comments
 (0)