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 c8c5b3d make sure compatible Router works fine c8c5b3d is described below commit c8c5b3d674fd88a67efdcb585c6fb2252f0794ee Author: ken.lj <ken.lj...@gmail.com> AuthorDate: Mon Dec 17 17:21:25 2018 +0800 make sure compatible Router works fine --- .../java/com/alibaba/dubbo/rpc/cluster/Router.java | 34 ++++++++++++++-- .../apache/dubbo/rpc/cluster/CompatibleRouter.java | 45 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Router.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Router.java index 8a27503..afe3252 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Router.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/Router.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL; 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.stream.Collectors; @@ -36,15 +37,40 @@ public interface Router extends org.apache.dubbo.rpc.cluster.Router { com.alibaba.dubbo.rpc.Invocation invocation) throws com.alibaba.dubbo.rpc.RpcException; + int compareTo(com.alibaba.dubbo.rpc.cluster.Router o); + + // Add since 2.7.0 @Override default <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { - List<com.alibaba.dubbo.rpc.Invoker<T>> invs = invokers.stream().map(invoker -> - new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<T>(invoker)). + List<com.alibaba.dubbo.rpc.Invoker<T>> invs = invokers.stream().map(invoker -> new com.alibaba.dubbo.rpc.Invoker.CompatibleInvoker<T>(invoker)). collect(Collectors.toList()); - List<com.alibaba.dubbo.rpc.Invoker<T>> res = this.route(invs, new com.alibaba.dubbo.common.URL(url), - new com.alibaba.dubbo.rpc.Invocation.CompatibleInvocation(invocation)); + List<com.alibaba.dubbo.rpc.Invoker<T>> res = this.route(invs, new com.alibaba.dubbo.common.URL(url), new com.alibaba.dubbo.rpc.Invocation.CompatibleInvocation(invocation)); return res.stream().map(inv -> inv.getOriginal()).collect(Collectors.toList()); } + + @Override + default void addRouterChain(RouterChain routerChain) { + } + + @Override + default boolean isRuntime() { + return true; + } + + @Override + default boolean isForce() { + return false; + } + + @Override + default int getPriority() { + return 1; + } + + @Override + default int compareTo(org.apache.dubbo.rpc.cluster.Router o) { + return compareTo((Router) o); + } } diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java b/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java new file mode 100644 index 0000000..14f5a0e --- /dev/null +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/CompatibleRouter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.cluster; + +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.rpc.Invocation; +import com.alibaba.dubbo.rpc.Invoker; +import com.alibaba.dubbo.rpc.RpcException; +import com.alibaba.dubbo.rpc.cluster.Router; + +import java.util.List; + +/** + * + */ +public class CompatibleRouter implements Router { + @Override + public URL getUrl() { + return null; + } + + @Override + public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { + return null; + } + + @Override + public int compareTo(Router o) { + return 0; + } +}