From e59711ddb6dcc93fe61bf4b09d45f6fe05fa546a Mon Sep 17 00:00:00 2001 From: xujingfeng Date: Thu, 17 Jan 2019 14:52:30 +0800 Subject: [PATCH] improve:remove spi of TagRouter --- .../rpc/cluster/router/tag/TagRouter.java | 6 - .../cluster/router/tag/TagRouterFactory.java | 31 -- ...om.alibaba.dubbo.rpc.cluster.RouterFactory | 3 +- .../rpc/cluster/router/tag/TagRouterTest.java | 24 +- .../dubbo/config/AbstractServiceConfig.java | 510 +++++++++--------- 5 files changed, 260 insertions(+), 314 deletions(-) delete mode 100644 dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterFactory.java diff --git a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java index d9d083d89077..b1b0d4f7a9d5 100644 --- a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -36,12 +36,6 @@ public class TagRouter extends AbstractRouter { private static final int DEFAULT_PRIORITY = 100; private static final URL ROUTER_URL = new URL("tag", Constants.ANYHOST_VALUE, 0, Constants.ANY_VALUE).addParameters(Constants.RUNTIME_KEY, "true"); - public TagRouter(URL url) { - this.url = url; - url.addParameters(Constants.RUNTIME_KEY, "true"); - this.priority = url.getParameter(Constants.PRIORITY_KEY, DEFAULT_PRIORITY); - } - public TagRouter() { this.url = ROUTER_URL; this.priority = url.getParameter(Constants.PRIORITY_KEY, DEFAULT_PRIORITY); diff --git a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterFactory.java b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterFactory.java deleted file mode 100644 index 08373afb99a3..000000000000 --- a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 com.alibaba.dubbo.rpc.cluster.router.tag; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.rpc.cluster.Router; -import com.alibaba.dubbo.rpc.cluster.RouterFactory; - -public class TagRouterFactory implements RouterFactory { - - public static final String NAME = "tag"; - - @Override - public Router getRouter(URL url) { - return new TagRouter(url); - } -} diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.rpc.cluster.RouterFactory b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.rpc.cluster.RouterFactory index 446cef30fee3..239c6f0b625a 100644 --- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.rpc.cluster.RouterFactory +++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.rpc.cluster.RouterFactory @@ -1,4 +1,3 @@ file=com.alibaba.dubbo.rpc.cluster.router.file.FileRouterFactory script=com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouterFactory -condition=com.alibaba.dubbo.rpc.cluster.router.condition.ConditionRouterFactory -tag=com.alibaba.dubbo.rpc.cluster.router.tag.TagRouterFactory \ No newline at end of file +condition=com.alibaba.dubbo.rpc.cluster.router.condition.ConditionRouterFactory \ No newline at end of file diff --git a/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java index a554c82f8388..7b400b7174b6 100644 --- a/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -37,13 +37,6 @@ public class TagRouterTest { - private URL tagUrl = new URL("tag" - , Constants.ANYHOST_VALUE, 0 - , Constants.ANY_VALUE) - .addParameters( - Constants.RUNTIME_KEY, "true" - ); - @BeforeClass public static void setUpBeforeClass() throws Exception { } @@ -71,7 +64,7 @@ public void testRoute_matchTag() { invokers.add(blueInvoker); invokers.add(defaultInvoker); - Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + Router tagRouter = new TagRouter(); List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertTrue(filteredInvokers.contains(redInvoker)); Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); @@ -99,7 +92,7 @@ public void testRoute_matchDefault() { invokers.add(blueInvoker); invokers.add(defaultInvoker); - Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + Router tagRouter = new TagRouter(); List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertTrue(filteredInvokers.contains(defaultInvoker)); Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); @@ -127,7 +120,7 @@ public void testRoute_requestWithTag_shouldDowngrade() { invokers.add(blueInvoker); invokers.add(defaultInvoker); - Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + Router tagRouter = new TagRouter(); List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertTrue(filteredInvokers.contains(defaultInvoker)); Assert.assertFalse(filteredInvokers.contains(yellowInvoker)); @@ -152,18 +145,9 @@ public void testRoute_requestWithoutTag_shouldNotDowngrade() { invokers.add(yellowInvoker); invokers.add(blueInvoker); - Router tagRouter = new TagRouterFactory().getRouter(tagUrl); + Router tagRouter = new TagRouter(); List> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); Assert.assertEquals(0, filteredInvokers.size()); } - @Test - public void testRoute_createBySpi() { - URL zkProvider = URL.valueOf("zookeeper://10.20.3.1:20880/com.foo.BarService?router=tag"); - String parameter = zkProvider.getParameter(Constants.ROUTER_KEY); - RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getExtension(parameter); - Router tagRouter = routerFactory.getRouter(zkProvider); - Assert.assertTrue(tagRouter instanceof TagRouter); - } - } diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractServiceConfig.java index 794600db74e5..7d242ff4c29c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractServiceConfig.java @@ -1,255 +1,255 @@ -/* - * 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 com.alibaba.dubbo.config; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.config.support.Parameter; -import com.alibaba.dubbo.rpc.ExporterListener; - -import java.util.Arrays; -import java.util.List; - -/** - * AbstractServiceConfig - * - * @export - */ -public abstract class AbstractServiceConfig extends AbstractInterfaceConfig { - - private static final long serialVersionUID = 1L; - - // version - protected String version; - - // group - protected String group; - - // whether the service is deprecated - protected Boolean deprecated; - - // delay service exporting - protected Integer delay; - - // whether to export the service - protected Boolean export; - - // weight - protected Integer weight; - - // document center - protected String document; - - // whether to register as a dynamic service or not on register center - protected Boolean dynamic; - - // whether to use token - protected String token; - - // access log - protected String accesslog; - protected List protocols; - // max allowed execute times - private Integer executes; - // whether to register - private Boolean register; - - // warm up period - private Integer warmup; - - // serialization - private String serialization; - - // provider tag - protected String tag; - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - checkKey("version", version); - this.version = version; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - checkKey("group", group); - this.group = group; - } - - public Integer getDelay() { - return delay; - } - - public void setDelay(Integer delay) { - this.delay = delay; - } - - public Boolean getExport() { - return export; - } - - public void setExport(Boolean export) { - this.export = export; - } - - public Integer getWeight() { - return weight; - } - - public void setWeight(Integer weight) { - this.weight = weight; - } - - @Parameter(escaped = true) - public String getDocument() { - return document; - } - - public void setDocument(String document) { - this.document = document; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - checkName("token", token); - this.token = token; - } - - public void setToken(Boolean token) { - if (token == null) { - setToken((String) null); - } else { - setToken(String.valueOf(token)); - } - } - - public Boolean isDeprecated() { - return deprecated; - } - - public void setDeprecated(Boolean deprecated) { - this.deprecated = deprecated; - } - - public Boolean isDynamic() { - return dynamic; - } - - public void setDynamic(Boolean dynamic) { - this.dynamic = dynamic; - } - - public List getProtocols() { - return protocols; - } - - @SuppressWarnings({"unchecked"}) - public void setProtocols(List protocols) { - this.protocols = (List) protocols; - } - - public ProtocolConfig getProtocol() { - return protocols == null || protocols.isEmpty() ? null : protocols.get(0); - } - - public void setProtocol(ProtocolConfig protocol) { - this.protocols = Arrays.asList(protocol); - } - - public String getAccesslog() { - return accesslog; - } - - public void setAccesslog(String accesslog) { - this.accesslog = accesslog; - } - - public void setAccesslog(Boolean accesslog) { - if (accesslog == null) { - setAccesslog((String) null); - } else { - setAccesslog(String.valueOf(accesslog)); - } - } - - public Integer getExecutes() { - return executes; - } - - public void setExecutes(Integer executes) { - this.executes = executes; - } - - @Override - @Parameter(key = Constants.SERVICE_FILTER_KEY, append = true) - public String getFilter() { - return super.getFilter(); - } - - @Override - @Parameter(key = Constants.EXPORTER_LISTENER_KEY, append = true) - public String getListener() { - return listener; - } - - @Override - public void setListener(String listener) { - checkMultiExtension(ExporterListener.class, "listener", listener); - this.listener = listener; - } - - public Boolean isRegister() { - return register; - } - - public void setRegister(Boolean register) { - this.register = register; - } - - public Integer getWarmup() { - return warmup; - } - - public void setWarmup(Integer warmup) { - this.warmup = warmup; - } - - public String getSerialization() { - return serialization; - } - - public void setSerialization(String serialization) { - this.serialization = serialization; - } - - @Parameter(key = "dubbo.tag") - public String getTag() { - return tag; - } - - public void setTag(String tag) { - this.tag = tag; - } - -} +/* + * 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 com.alibaba.dubbo.config; + +import com.alibaba.dubbo.common.Constants; +import com.alibaba.dubbo.config.support.Parameter; +import com.alibaba.dubbo.rpc.ExporterListener; + +import java.util.Arrays; +import java.util.List; + +/** + * AbstractServiceConfig + * + * @export + */ +public abstract class AbstractServiceConfig extends AbstractInterfaceConfig { + + private static final long serialVersionUID = 1L; + + // version + protected String version; + + // group + protected String group; + + // whether the service is deprecated + protected Boolean deprecated; + + // delay service exporting + protected Integer delay; + + // whether to export the service + protected Boolean export; + + // weight + protected Integer weight; + + // document center + protected String document; + + // whether to register as a dynamic service or not on register center + protected Boolean dynamic; + + // whether to use token + protected String token; + + // access log + protected String accesslog; + protected List protocols; + // max allowed execute times + private Integer executes; + // whether to register + private Boolean register; + + // warm up period + private Integer warmup; + + // serialization + private String serialization; + + // provider tag + protected String tag; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + checkKey("version", version); + this.version = version; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + checkKey("group", group); + this.group = group; + } + + public Integer getDelay() { + return delay; + } + + public void setDelay(Integer delay) { + this.delay = delay; + } + + public Boolean getExport() { + return export; + } + + public void setExport(Boolean export) { + this.export = export; + } + + public Integer getWeight() { + return weight; + } + + public void setWeight(Integer weight) { + this.weight = weight; + } + + @Parameter(escaped = true) + public String getDocument() { + return document; + } + + public void setDocument(String document) { + this.document = document; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + checkName("token", token); + this.token = token; + } + + public void setToken(Boolean token) { + if (token == null) { + setToken((String) null); + } else { + setToken(String.valueOf(token)); + } + } + + public Boolean isDeprecated() { + return deprecated; + } + + public void setDeprecated(Boolean deprecated) { + this.deprecated = deprecated; + } + + public Boolean isDynamic() { + return dynamic; + } + + public void setDynamic(Boolean dynamic) { + this.dynamic = dynamic; + } + + public List getProtocols() { + return protocols; + } + + @SuppressWarnings({"unchecked"}) + public void setProtocols(List protocols) { + this.protocols = (List) protocols; + } + + public ProtocolConfig getProtocol() { + return protocols == null || protocols.isEmpty() ? null : protocols.get(0); + } + + public void setProtocol(ProtocolConfig protocol) { + this.protocols = Arrays.asList(protocol); + } + + public String getAccesslog() { + return accesslog; + } + + public void setAccesslog(String accesslog) { + this.accesslog = accesslog; + } + + public void setAccesslog(Boolean accesslog) { + if (accesslog == null) { + setAccesslog((String) null); + } else { + setAccesslog(String.valueOf(accesslog)); + } + } + + public Integer getExecutes() { + return executes; + } + + public void setExecutes(Integer executes) { + this.executes = executes; + } + + @Override + @Parameter(key = Constants.SERVICE_FILTER_KEY, append = true) + public String getFilter() { + return super.getFilter(); + } + + @Override + @Parameter(key = Constants.EXPORTER_LISTENER_KEY, append = true) + public String getListener() { + return listener; + } + + @Override + public void setListener(String listener) { + checkMultiExtension(ExporterListener.class, "listener", listener); + this.listener = listener; + } + + public Boolean isRegister() { + return register; + } + + public void setRegister(Boolean register) { + this.register = register; + } + + public Integer getWarmup() { + return warmup; + } + + public void setWarmup(Integer warmup) { + this.warmup = warmup; + } + + public String getSerialization() { + return serialization; + } + + public void setSerialization(String serialization) { + this.serialization = serialization; + } + + @Parameter(key = "dubbo.tag") + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + +}