diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java index cc99a87598..3cd3edeb9c 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java @@ -38,6 +38,11 @@ public class MockDirInvocation implements Invocation { return "echo"; } + @Override + public String getServiceName() { + return "DemoService"; + } + public Class[] getParameterTypes() { return new Class[]{String.class}; } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java index a88a759161..c7ffe66b47 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java @@ -89,7 +89,7 @@ public class ConditionRouterTest { public void testRoute_matchFilter() { List> invokers = new ArrayList>(); Invoker invoker1 = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.3:20880/com.foo.BarService?default.serialization=fastjson")); + "dubbo://10.10.3.3:20880/com.foo.BarService?default.serialization=fastjson")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() @@ -102,19 +102,19 @@ public class ConditionRouterTest { System.err.println(invoker3.getUrl().getAddress()); Router router1 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.3").addParameter(FORCE_KEY, + "host = " + NetUtils.getLocalHost() + " => " + " host = 10.10.3.3").addParameter(FORCE_KEY, String.valueOf(true))); Router router2 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.* & host != 10.20.3.3").addParameter( + "host = " + NetUtils.getLocalHost() + " => " + " host = 10.10.3.* & host != 10.10.3.3").addParameter( FORCE_KEY, String.valueOf(true))); Router router3 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.3 & host != 10.20.3.3").addParameter( + "host = " + NetUtils.getLocalHost() + " => " + " host = 10.10.3.3 & host != 10.10.3.3").addParameter( FORCE_KEY, String.valueOf(true))); Router router4 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.2,10.20.3.3,10.20.3.4").addParameter( + "host = " + NetUtils.getLocalHost() + " => " + " host = 10.10.3.2,10.10.3.3,10.10.3.4").addParameter( FORCE_KEY, String.valueOf(true))); Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host != 10.20.3.3").addParameter(FORCE_KEY, + "host = " + NetUtils.getLocalHost() + " => " + " host != 10.10.3.3").addParameter(FORCE_KEY, String.valueOf(true))); Router router6 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " => " + " serialization = fastjson").addParameter( @@ -138,7 +138,7 @@ public class ConditionRouterTest { @Test public void testRoute_methodRoute() { - Invocation invocation = new RpcInvocation("getFoo", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("getFoo", "com.foo.BarService", new Class[0], new Object[0]); // More than one methods, mismatch Router router = new ConditionRouterFactory().getRouter(getRouteUrl("methods=getFoo => host = 1.2.3.4")); boolean matchWhen = ((ConditionRouter) router).matchWhen( @@ -162,7 +162,7 @@ public class ConditionRouterTest { Assertions.assertTrue(matchWhen); // Test filter condition List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() @@ -172,14 +172,14 @@ public class ConditionRouterTest { invokers.add(invoker3); Router router4 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " & methods = getFoo => " + " host = 10.20.3.3").addParameter( + "host = " + NetUtils.getLocalHost() + " & methods = getFoo => " + " host = 10.10.3.3").addParameter( FORCE_KEY, String.valueOf(true))); List> filteredInvokers1 = router4.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation); Assertions.assertEquals(1, filteredInvokers1.size()); Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " & methods = unvalidmethod => " + " host = 10.20.3.3") + "host = " + NetUtils.getLocalHost() + " & methods = unvalidmethod => " + " host = 10.10.3.3") .addParameter(FORCE_KEY, String.valueOf(true))); List> filteredInvokers2 = router5.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation); @@ -224,7 +224,7 @@ public class ConditionRouterTest { public void testRoute_HostFilter() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost())); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); @@ -240,7 +240,7 @@ public class ConditionRouterTest { public void testRoute_Empty_HostFilter() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " host = " + NetUtils.getLocalHost())); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); @@ -256,7 +256,7 @@ public class ConditionRouterTest { public void testRoute_False_HostFilter() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " host = " + NetUtils.getLocalHost())); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); @@ -272,7 +272,7 @@ public class ConditionRouterTest { public void testRoute_Placeholder() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = $host")); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); @@ -288,7 +288,7 @@ public class ConditionRouterTest { public void testRoute_NoForce() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4")); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); @@ -302,7 +302,7 @@ public class ConditionRouterTest { public void testRoute_Force() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4").addParameter(FORCE_KEY, String.valueOf(true))); List> invokers = new ArrayList>(); - Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); + Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.10.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); Invoker invoker3 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); invokers.add(invoker1); diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java index 37402d8d9a..9a8f77faea 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java @@ -47,10 +47,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_AVAILABLE_CHECK_KEY; import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -493,21 +493,21 @@ public class AbstractClusterInvokerTest { Directory directory = new StaticDirectory(invokers); FailoverClusterInvoker failoverClusterInvoker = new FailoverClusterInvoker(directory); try { - failoverClusterInvoker.invoke(new RpcInvocation("sayHello", new Class[0], new Object[0])); + failoverClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), new Class[0], new Object[0])); Assertions.fail(); } catch (RpcException e) { Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); } ForkingClusterInvoker forkingClusterInvoker = new ForkingClusterInvoker(directory); try { - forkingClusterInvoker.invoke(new RpcInvocation("sayHello", new Class[0], new Object[0])); + forkingClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), new Class[0], new Object[0])); Assertions.fail(); } catch (RpcException e) { Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); } FailfastClusterInvoker failfastClusterInvoker = new FailfastClusterInvoker(directory); try { - failfastClusterInvoker.invoke(new RpcInvocation("sayHello", new Class[0], new Object[0])); + failfastClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), new Class[0], new Object[0])); Assertions.fail(); } catch (RpcException e) { Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java index d283c63b26..fde22937b4 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java @@ -38,6 +38,11 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation { } + @Override + default String getServiceName() { + return null; + } + class CompatibleInvocation implements Invocation, org.apache.dubbo.rpc.Invocation { private org.apache.dubbo.rpc.Invocation delegate; diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java index d7db04fe10..378f14adc2 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import java.lang.reflect.Type; -import java.util.Map; /** * 2019-04-18 @@ -76,8 +75,4 @@ public class RpcUtils extends org.apache.dubbo.rpc.support.RpcUtils { public static boolean isOneway(URL url, Invocation inv) { return org.apache.dubbo.rpc.support.RpcUtils.isOneway(url.getOriginalURL(), inv); } - - public static Map getNecessaryAttachments(Invocation inv) { - return org.apache.dubbo.rpc.support.RpcUtils.getNecessaryAttachments(inv); - } } diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java index 9c811f5c9e..fa97ff5cf2 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java @@ -17,7 +17,7 @@ package org.apache.dubbo.config; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; +import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.service.Person; import com.alibaba.dubbo.config.ArgumentConfig; @@ -113,7 +113,7 @@ public class MethodConfigTest { methodConfig.setOninvokeMethod("setName"); methodConfig.setOninvoke(new Person()); - ConsumerMethodModel.AsyncMethodInfo methodInfo = org.apache.dubbo.config.MethodConfig.convertMethodConfig2AyncInfo(methodConfig); + ConsumerModel.AsyncMethodInfo methodInfo = org.apache.dubbo.config.MethodConfig.convertMethodConfig2AyncInfo(methodConfig); assertEquals(methodInfo.getOninvokeMethod(), Person.class.getMethod("setName", String.class)); } diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java index 0834746676..b48b4295e3 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java @@ -44,6 +44,11 @@ public class MockInvocation implements Invocation { return "echo"; } + @Override + public String getServiceName() { + return "DemoService"; + } + public Class[] getParameterTypes() { return new Class[]{String.class}; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index e1018108a5..5786b5d923 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -30,7 +30,7 @@ import org.apache.dubbo.common.utils.MethodUtils; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; +import org.apache.dubbo.rpc.model.ConsumerModel; import java.io.Serializable; import java.lang.reflect.Method; @@ -245,7 +245,7 @@ public abstract class AbstractConfig implements Serializable { } } - protected static ConsumerMethodModel.AsyncMethodInfo convertMethodConfig2AyncInfo(MethodConfig methodConfig) { + protected static ConsumerModel.AsyncMethodInfo convertMethodConfig2AyncInfo(MethodConfig methodConfig) { if (methodConfig == null || (methodConfig.getOninvoke() == null && methodConfig.getOnreturn() == null && methodConfig.getOnthrow() == null)) { return null; } @@ -255,7 +255,7 @@ public abstract class AbstractConfig implements Serializable { throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been set."); } - ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = new ConsumerMethodModel.AsyncMethodInfo(); + ConsumerModel.AsyncMethodInfo asyncMethodInfo = new ConsumerModel.AsyncMethodInfo(); asyncMethodInfo.setOninvokeInstance(methodConfig.getOninvoke()); asyncMethodInfo.setOnreturnInstance(methodConfig.getOnreturn()); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index a3c020ceec..c4a66a4b35 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -46,7 +46,6 @@ import org.apache.dubbo.rpc.support.ProtocolUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -56,24 +55,24 @@ import java.util.Map; import java.util.Properties; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; -import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; -import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; -import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; -import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; -import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; +import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; +import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; +import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL; +import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; /** * ReferenceConfig @@ -304,7 +303,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { appendParameters(map, this); Map attributes = null; if (CollectionUtils.isNotEmpty(methods)) { - attributes = new HashMap(); + attributes = new HashMap<>(); for (MethodConfig methodConfig : methods) { appendParameters(map, methodConfig, methodConfig.getName()); String retryKey = methodConfig.getName() + ".retry"; @@ -334,17 +333,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { } private ConsumerModel buildConsumerModel(String serviceKey, Map attributes) { - Method[] methods = interfaceClass.getMethods(); - Class serviceInterface = interfaceClass; - if (interfaceClass == GenericService.class) { - try { - serviceInterface = Class.forName(interfaceName); - methods = serviceInterface.getMethods(); - } catch (ClassNotFoundException e) { - methods = interfaceClass.getMethods(); - } - } - return new ConsumerModel(serviceKey, serviceInterface, ref, methods, attributes); + return new ConsumerModel(serviceKey, interfaceClass, ref, ApplicationModel.registerServiceModel(interfaceClass), attributes); } @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 257d2a15ee..2b16496d5a 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -65,33 +65,33 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND; -import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; -import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; -import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; -import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY; -import static org.apache.dubbo.config.Constants.MULTICAST; -import static org.apache.dubbo.config.Constants.PROTOCOLS_SUFFIX; -import static org.apache.dubbo.rpc.Constants.SCOPE_KEY; -import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL; -import static org.apache.dubbo.config.Constants.SCOPE_NONE; -import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE; -import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; -import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; -import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL; -import static org.apache.dubbo.rpc.Constants.PROXY_KEY; -import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort; import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidPort; +import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; +import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; +import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; +import static org.apache.dubbo.config.Constants.MULTICAST; +import static org.apache.dubbo.config.Constants.PROTOCOLS_SUFFIX; +import static org.apache.dubbo.config.Constants.SCOPE_NONE; +import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; +import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL; +import static org.apache.dubbo.rpc.Constants.PROXY_KEY; +import static org.apache.dubbo.rpc.Constants.SCOPE_KEY; +import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL; +import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE; +import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY; /** * ServiceConfig @@ -452,7 +452,7 @@ public class ServiceConfig extends AbstractServiceConfig { List registryURLs = loadRegistries(true); for (ProtocolConfig protocolConfig : protocols) { String pathKey = URL.buildKey(getContextPath(protocolConfig).map(p -> p + "/" + path).orElse(path), group, version); - ProviderModel providerModel = new ProviderModel(pathKey, ref, interfaceClass); + ProviderModel providerModel = new ProviderModel(pathKey, ref, ApplicationModel.registerServiceModel(interfaceClass)); ApplicationModel.initProviderModel(pathKey, providerModel); doExportUrlsFor1Protocol(protocolConfig, registryURLs); } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java index b9b5c45d43..0444e4fa2a 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java @@ -132,7 +132,7 @@ public class CacheTest { parameters.put("findCache.cache", "threadlocal"); URL url = new URL("dubbo", "127.0.0.1", 29582, "org.apache.dubbo.config.cache.CacheService", parameters); - Invocation invocation = new RpcInvocation("findCache", new Class[]{String.class}, new String[]{"0"}, null, null); + Invocation invocation = new RpcInvocation("findCache", "org.apache.dubbo.config.cache.CacheService", new Class[]{String.class}, new String[]{"0"}, null, null); Cache cache = cacheFactory.getCache(url, invocation); assertTrue(cache instanceof ThreadLocalCache); diff --git a/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/DemoService.java b/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/DemoService.java index 1172c9be0f..32337acdfd 100644 --- a/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/DemoService.java +++ b/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/DemoService.java @@ -16,8 +16,14 @@ */ package org.apache.dubbo.demo; +import java.util.concurrent.CompletableFuture; + public interface DemoService { String sayHello(String name); + default CompletableFuture sayHelloAsync(String name) { + return CompletableFuture.completedFuture(sayHello(name)); + } + } \ No newline at end of file diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java index 90ed7c0b6a..955d3eb5a3 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java @@ -20,16 +20,18 @@ import org.apache.dubbo.demo.DemoService; import org.springframework.context.support.ClassPathXmlApplicationContext; +import java.util.concurrent.CompletableFuture; + public class Application { /** * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before * launch the application */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); context.start(); DemoService demoService = context.getBean("demoService", DemoService.class); - String hello = demoService.sayHello("world"); - System.out.println("result: " + hello); + CompletableFuture hello = demoService.sayHelloAsync("world"); + System.out.println("result: " + hello.get()); } } diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java index 25a9dd4be0..f35f82ad92 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.demo.provider; +import org.apache.dubbo.common.utils.ReflectUtils; + import org.springframework.context.support.ClassPathXmlApplicationContext; public class Application { @@ -25,6 +27,7 @@ public class Application { */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml"); + System.err.println(ReflectUtils.getDesc(new Class[]{String.class, String[].class, Object[].class})); context.start(); System.in.read(); } diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java index d0d315c9b4..31b9040072 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java @@ -22,6 +22,8 @@ import org.apache.dubbo.rpc.RpcContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.CompletableFuture; + public class DemoServiceImpl implements DemoService { private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class); @@ -31,4 +33,16 @@ public class DemoServiceImpl implements DemoService { return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); } + @Override + public CompletableFuture sayHelloAsync(String name) { + CompletableFuture cf = CompletableFuture.supplyAsync(() -> { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return "async result"; + }); + return cf; + } } diff --git a/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java b/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java index a24711fdda..0a75b9a212 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java @@ -40,8 +40,8 @@ import java.util.List; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; -import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -118,7 +118,7 @@ public class MonitorFilterTest { public void testFilter() throws Exception { MonitorFilter monitorFilter = new MonitorFilter(); monitorFilter.setMonitorFactory(monitorFactory); - Invocation invocation = new RpcInvocation("aaa", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("aaa", MonitorService.class.getName(), new Class[0], new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); Result result = monitorFilter.invoke(serviceInvoker, invocation); result.thenApplyWithContext((r) -> { @@ -145,7 +145,7 @@ public class MonitorFilterTest { MonitorFilter monitorFilter = new MonitorFilter(); MonitorFactory mockMonitorFactory = mock(MonitorFactory.class); monitorFilter.setMonitorFactory(mockMonitorFactory); - Invocation invocation = new RpcInvocation("aaa", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("aaa", MonitorService.class.getName(), new Class[0], new Object[0]); Invoker invoker = mock(Invoker.class); given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE)); @@ -158,7 +158,7 @@ public class MonitorFilterTest { public void testGenericFilter() throws Exception { MonitorFilter monitorFilter = new MonitorFilter(); monitorFilter.setMonitorFactory(monitorFactory); - Invocation invocation = new RpcInvocation("$invoke", new Class[]{String.class, String[].class, Object[].class}, new Object[]{"xxx", new String[]{}, new Object[]{}}); + Invocation invocation = new RpcInvocation("$invoke", MonitorService.class.getName(), new Class[]{String.class, String[].class, Object[].class}, new Object[]{"xxx", new String[]{}, new Object[]{}}); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); Result result = monitorFilter.invoke(serviceInvoker, invocation); result.thenApplyWithContext((r) -> { @@ -189,7 +189,7 @@ public class MonitorFilterTest { monitorFilter.setMonitorFactory(mockMonitorFactory); given(mockMonitorFactory.getMonitor(any(URL.class))).willReturn(mockMonitor); - Invocation invocation = new RpcInvocation("aaa", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("aaa", MonitorService.class.getName(), new Class[0], new Object[0]); monitorFilter.invoke(serviceInvoker, invocation); } diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java index 591296fa44..20460d53b1 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java @@ -25,9 +25,10 @@ import org.apache.dubbo.monitor.support.AbstractMonitorFactory; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.rpc.model.ApplicationModel; -import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.remoting.Constants.CHECK_KEY; import static org.apache.dubbo.rpc.Constants.REFERENCE_FILTER_KEY; @@ -63,6 +64,7 @@ public class DubboMonitorFactory extends AbstractMonitorFactory { } urlBuilder.addParameters(CHECK_KEY, String.valueOf(false), REFERENCE_FILTER_KEY, filter + "-monitor"); + ApplicationModel.registerServiceModel(MonitorService.class); Invoker monitorInvoker = protocol.refer(MonitorService.class, urlBuilder.build()); MonitorService monitorService = proxyFactory.getProxy(monitorInvoker); return new DubboMonitor(monitorInvoker, monitorService); diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java index 761de5945d..97b75d5ff4 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java @@ -31,6 +31,7 @@ import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.support.RpcUtils; import com.alibaba.fastjson.JSON; @@ -88,6 +89,7 @@ public class MetricsFilter implements Filter { Invoker metricsInvoker = initMetricsInvoker(); try { + ApplicationModel.registerServiceModel(MetricsService.class); protocol.export(metricsInvoker); } catch (RuntimeException e) { logger.error("Metrics Service need to be configured" + diff --git a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java index 47b607db7f..4bf8a4c393 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java @@ -112,7 +112,7 @@ public class MetricsFilterTest { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation invocation = new RpcInvocation("sayName", new Class[]{Integer.class}, new Object[0]); + Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), new Class[]{Integer.class}, new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE)); for (int i = 0; i < 100; i++) { @@ -137,7 +137,7 @@ public class MetricsFilterTest { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation invocation = new RpcInvocation("timeoutException", null, null); + Invocation invocation = new RpcInvocation("timeoutException", DemoService.class.getName(), null, null); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); RpcContext.getContext().setUrl(timeoutInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE) .addParameter(TIMEOUT_KEY, 300)); @@ -167,7 +167,7 @@ public class MetricsFilterTest { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation invocation = new RpcInvocation("sayName", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), new Class[0], new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER)); for (int i = 0; i < 100; i++) { @@ -191,7 +191,7 @@ public class MetricsFilterTest { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation invocation = new RpcInvocation("sayName", new Class[0], new Object[0]); + Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), new Class[0], new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER_SIDE) .addParameter(TIMEOUT_KEY, 300)); @@ -206,7 +206,7 @@ public class MetricsFilterTest { Protocol protocol = new DubboProtocol(); URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":20880/" + MetricsService.class.getName()); Invoker invoker = protocol.refer(MetricsService.class, url); - invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{DUBBO_GROUP}); + invocation = new RpcInvocation("getMetricsByGroup", DemoService.class.getName(), new Class[]{String.class}, new Object[]{DUBBO_GROUP}); try { Thread.sleep(5000); } catch (Exception e) { @@ -235,8 +235,8 @@ public class MetricsFilterTest { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation sayNameInvocation = new RpcInvocation("sayName", new Class[0], new Object[0]); - Invocation echoInvocation = new RpcInvocation("echo", new Class[]{Integer.class}, new Integer[]{1}); + Invocation sayNameInvocation = new RpcInvocation("sayName", DemoService.class.getName(), new Class[0], new Object[0]); + Invocation echoInvocation = new RpcInvocation("echo", DemoService.class.getName(), new Class[]{Integer.class}, new Integer[]{1}); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER_SIDE) .addParameter(TIMEOUT_KEY, 300)); @@ -258,7 +258,7 @@ public class MetricsFilterTest { Protocol protocol = new DubboProtocol(); URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":20880/" + MetricsService.class.getName()); Invoker invoker = protocol.refer(MetricsService.class, url); - Invocation invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{DUBBO_GROUP}); + Invocation invocation = new RpcInvocation("getMetricsByGroup", DemoService.class.getName(), new Class[]{String.class}, new Object[]{DUBBO_GROUP}); try { Thread.sleep(15000); } catch (Exception e) { diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java index 469a40a339..ca23068abb 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java @@ -57,7 +57,7 @@ public class Ls implements BaseCommand { //Content for (ProviderModel providerModel : providerModelList) { - tTable.addRow(providerModel.getServiceName(), isRegistered(providerModel.getServiceName()) ? "Y" : "N"); + tTable.addRow(providerModel.getServiceKey(), isRegistered(providerModel.getServiceKey()) ? "Y" : "N"); } stringBuilder.append(tTable.rendering()); @@ -80,7 +80,7 @@ public class Ls implements BaseCommand { //Content //TODO to calculate consumerAddressNum for (ConsumerModel consumerModel : consumerModelList) { - tTable.addRow(consumerModel.getServiceName(), getConsumerAddressNum(consumerModel.getServiceName())); + tTable.addRow(consumerModel.getServiceKey(), getConsumerAddressNum(consumerModel.getServiceKey())); } stringBuilder.append(tTable.rendering()); diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java index 79c41f3b66..cf2862e36e 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Offline.java @@ -51,9 +51,9 @@ public class Offline implements BaseCommand { Collection providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { - if (providerModel.getServiceName().matches(servicePattern)) { + if (providerModel.getServiceKey().matches(servicePattern)) { hasService = true; - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); + Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceKey()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (!providerInvokerWrapper.isReg()) { continue; diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java index 30ba14b6fe..6bcf089464 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Online.java @@ -53,9 +53,9 @@ public class Online implements BaseCommand { Collection providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { - if (providerModel.getServiceName().matches(servicePattern)) { + if (providerModel.getServiceKey().matches(servicePattern)) { hasService = true; - Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); + Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceKey()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (providerInvokerWrapper.isReg()) { continue; diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java index c82e2d5d68..4b4fda2a71 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/LsTest.java @@ -25,14 +25,15 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ProviderModel; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.Map; import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,9 +41,9 @@ public class LsTest { @Test public void testExecute() throws Exception { ConsumerModel consumerModel = mock(ConsumerModel.class); - when(consumerModel.getServiceName()).thenReturn("org.apache.dubbo.FooService"); + when(consumerModel.getServiceKey()).thenReturn("org.apache.dubbo.FooService"); ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initConsumerModel("org.apache.dubbo.FooService", consumerModel); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java index f498d5aeb3..6f6be8e0bb 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OfflineTest.java @@ -24,13 +24,14 @@ import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.Is.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,7 +39,7 @@ public class OfflineTest { @Test public void testExecute() throws Exception { ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); Invoker providerInvoker = mock(Invoker.class); diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java index 71132c0955..b419f0ca9f 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/OnlineTest.java @@ -24,11 +24,12 @@ import org.apache.dubbo.registry.support.ProviderInvokerWrapper; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ProviderModel; + import org.junit.jupiter.api.Test; import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -37,7 +38,7 @@ public class OnlineTest { @Test public void testExecute() throws Exception { ProviderModel providerModel = mock(ProviderModel.class); - when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); + when(providerModel.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); Invoker providerInvoker = mock(Invoker.class); diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java index 7bf8197bff..e64a1bf8a4 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java @@ -34,6 +34,7 @@ import org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance; import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance; import org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory; import org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker; +import org.apache.dubbo.rpc.service.GenericService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -49,19 +50,12 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; -import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; -import static org.apache.dubbo.rpc.cluster.Constants.LOADBALANCE_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.MOCK_PROTOCOL; -import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.RULE_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.TYPE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.DISABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; @@ -70,6 +64,13 @@ import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGO import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; import static org.apache.dubbo.rpc.Constants.$INVOKE; import static org.apache.dubbo.rpc.Constants.MOCK_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; +import static org.apache.dubbo.rpc.cluster.Constants.LOADBALANCE_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.MOCK_PROTOCOL; +import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.RULE_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.TYPE_KEY; import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -482,7 +483,7 @@ public class RegistryDirectoryTest { registryDirectory.notify(serviceUrls); // Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException; - invocation = new RpcInvocation($INVOKE, new Class[]{String.class, String[].class, Object[].class}, + invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), new Class[]{String.class, String[].class, Object[].class}, new Object[]{"getXXX1", "", new Object[]{}}); List invokers = registryDirectory.list(invocation); @@ -511,7 +512,7 @@ public class RegistryDirectoryTest { registryDirectory.notify(serviceUrls); - invocation = new RpcInvocation($INVOKE, + invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), new Class[]{String.class, String[].class, Object[].class}, new Object[]{"getXXX1", new String[]{"Enum"}, new Object[]{Param.MORGAN}}); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java index 058e0ad09c..23f6f63b17 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java @@ -35,6 +35,13 @@ public interface Invocation { */ String getMethodName(); + + /** + * get the interface name + * @return + */ + String getServiceName(); + /** * get parameter types. * diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index 06b7cb6a0d..d7eb9234d5 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -18,9 +18,11 @@ package org.apache.dubbo.rpc; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.rpc.model.ApplicationModel; import java.io.Serializable; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -43,8 +45,10 @@ public class RpcInvocation implements Invocation, Serializable { private static final long serialVersionUID = -4355285085441097045L; private String methodName; + private String serviceName; - private Class[] parameterTypes; + private transient Class[] parameterTypes; + private String parameterTypesDesc; private Object[] arguments; @@ -54,13 +58,15 @@ public class RpcInvocation implements Invocation, Serializable { private transient Class returnType; + private transient Type[] returnTypes; + private transient InvokeMode invokeMode; public RpcInvocation() { } public RpcInvocation(Invocation invocation, Invoker invoker) { - this(invocation.getMethodName(), invocation.getParameterTypes(), + this(invocation.getMethodName(), invocation.getServiceName(), invocation.getParameterTypes(), invocation.getArguments(), new HashMap(invocation.getAttachments()), invocation.getInvoker()); if (invoker != null) { @@ -88,33 +94,40 @@ public class RpcInvocation implements Invocation, Serializable { } public RpcInvocation(Invocation invocation) { - this(invocation.getMethodName(), invocation.getParameterTypes(), + this(invocation.getMethodName(), invocation.getServiceName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); } - public RpcInvocation(Method method, Object[] arguments) { - this(method.getName(), method.getParameterTypes(), arguments, null, null); + public RpcInvocation(Method method, String serviceName, Object[] arguments) { + this(method, serviceName, arguments, null); } - public RpcInvocation(Method method, Object[] arguments, Map attachment) { - this(method.getName(), method.getParameterTypes(), arguments, attachment, null); + public RpcInvocation(Method method, String serviceName, Object[] arguments, Map attachment) { + this(method.getName(), serviceName, method.getParameterTypes(), arguments, attachment, null); this.returnType = method.getReturnType(); } - public RpcInvocation(String methodName, Class[] parameterTypes, Object[] arguments) { - this(methodName, parameterTypes, arguments, null, null); + public RpcInvocation(String methodName, String serviceName, Class[] parameterTypes, Object[] arguments) { + this(methodName, serviceName, parameterTypes, arguments, null, null); } - public RpcInvocation(String methodName, Class[] parameterTypes, Object[] arguments, Map attachments) { - this(methodName, parameterTypes, arguments, attachments, null); + public RpcInvocation(String methodName, String serviceName, Class[] parameterTypes, Object[] arguments, Map attachments) { + this(methodName, serviceName, parameterTypes, arguments, attachments, null); } - public RpcInvocation(String methodName, Class[] parameterTypes, Object[] arguments, Map attachments, Invoker invoker) { + public RpcInvocation(String methodName, String serviceName, Class[] parameterTypes, Object[] arguments, Map attachments, Invoker invoker) { this.methodName = methodName; this.parameterTypes = parameterTypes == null ? new Class[0] : parameterTypes; this.arguments = arguments == null ? new Object[0] : arguments; this.attachments = attachments == null ? new HashMap() : attachments; this.invoker = invoker; + ApplicationModel.getServiceModel(serviceName).ifPresent(serviceModel -> + serviceModel.getMethod(methodName, parameterTypes) + .ifPresent(methodModel -> { + this.parameterTypesDesc = methodModel.getParamDesc(); + this.returnTypes = methodModel.getReturnTypes(); + }) + ); } @Override @@ -131,6 +144,15 @@ public class RpcInvocation implements Invocation, Serializable { return methodName; } + @Override + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + public void setMethodName(String methodName) { this.methodName = methodName; } @@ -144,6 +166,14 @@ public class RpcInvocation implements Invocation, Serializable { this.parameterTypes = parameterTypes == null ? new Class[0] : parameterTypes; } + public String getParameterTypesDesc() { + return parameterTypesDesc; + } + + public void setParameterTypesDesc(String parameterTypesDesc) { + this.parameterTypesDesc = parameterTypesDesc; + } + @Override public Object[] getArguments() { return arguments; @@ -227,6 +257,14 @@ public class RpcInvocation implements Invocation, Serializable { this.returnType = returnType; } + public Type[] getReturnTypes() { + return returnTypes; + } + + public void setReturnTypes(Type[] returnTypes) { + this.returnTypes = returnTypes; + } + public InvokeMode getInvokeMode() { return invokeMode; } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index ed6e123971..037734e6cf 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -138,7 +138,7 @@ public class GenericFilter extends ListenableFilter { args[0].getClass().getName()); } } - return invoker.invoke(new RpcInvocation(method, args, inv.getAttachments())); + return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args, inv.getAttachments())); } catch (NoSuchMethodException e) { throw new RpcException(e.getMessage(), e); } catch (ClassNotFoundException e) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java index 0fd0d826df..06710bc1d5 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java @@ -54,6 +54,8 @@ public class GenericImplFilter extends ListenableFilter { private static final Class[] GENERIC_PARAMETER_TYPES = new Class[]{String.class, String[].class, Object[].class}; + private static final String GENERIC_PARAMETER_DESC = "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;"; + public GenericImplFilter() { super.listener = new GenericImplListener(); } @@ -90,6 +92,7 @@ public class GenericImplFilter extends ListenableFilter { invocation2.setMethodName($INVOKE); } invocation2.setParameterTypes(GENERIC_PARAMETER_TYPES); + invocation2.setParameterTypesDesc(GENERIC_PARAMETER_DESC); invocation2.setArguments(new Object[]{methodName, types, args}); return invoker.invoke(invocation2); } else if ((invocation.getMethodName().equals($INVOKE) || invocation.getMethodName().equals($INVOKE_ASYNC)) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java index 33dcc908e1..22663513e1 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -37,14 +38,21 @@ public class ApplicationModel { protected static final Logger LOGGER = LoggerFactory.getLogger(ApplicationModel.class); /** - * full qualified class name -> provided service + * serviceKey -> exported service + * each service may has different group, version, path, instance and so on, but they point to the same {@link ServiceModel} */ private static final ConcurrentMap PROVIDED_SERVICES = new ConcurrentHashMap<>(); /** - * full qualified class name -> subscribe service + * serviceKey -> referred service + * each service may has different group, version, path, instance and so on, but they point to the same {@link ServiceModel} */ private static final ConcurrentMap CONSUMED_SERVICES = new ConcurrentHashMap<>(); + /** + * The description of a unique service (interface definition in Dubbo) + */ + private static final ConcurrentHashMap SERVICES = new ConcurrentHashMap<>(); + private static String application; public static Collection allConsumerModels() { @@ -55,12 +63,12 @@ public class ApplicationModel { return PROVIDED_SERVICES.values(); } - public static ProviderModel getProviderModel(String serviceName) { - return PROVIDED_SERVICES.get(serviceName); + public static ProviderModel getProviderModel(String serviceKey) { + return PROVIDED_SERVICES.get(serviceKey); } - public static ConsumerModel getConsumerModel(String serviceName) { - return CONSUMED_SERVICES.get(serviceName); + public static ConsumerModel getConsumerModel(String serviceKey) { + return CONSUMED_SERVICES.get(serviceKey); } public static void initConsumerModel(String serviceName, ConsumerModel consumerModel) { @@ -75,6 +83,38 @@ public class ApplicationModel { } } + public static ServiceModel registerServiceModel(Class interfaceClass) { + return SERVICES.computeIfAbsent(interfaceClass.getName(), (k) -> new ServiceModel(interfaceClass)); + } + + /** + * See {@link #registerServiceModel(Class)} + * + * we assume: + * 1. services with different interface are not allowed to have the same path. + * 2. services with the same interface but different group/version can share the same path. + * 3. path's default value is the name of the interface. + * @param path + * @param interfaceClass + * @return + */ + public static ServiceModel registerServiceModel(String path, Class interfaceClass) { + ServiceModel serviceModel = registerServiceModel(interfaceClass); + // register path + if (!interfaceClass.getName().equals(path)) { + SERVICES.putIfAbsent(path, serviceModel); + } + return serviceModel; + } + + public static Optional getServiceModel (String interfaceName) { + return Optional.ofNullable(SERVICES.get(interfaceName)); + } + + public static Optional getServiceModel (Class interfaceClass) { + return Optional.ofNullable(SERVICES.get(interfaceClass.getName())); + } + public static String getApplication() { return application; } @@ -90,4 +130,5 @@ public class ApplicationModel { PROVIDED_SERVICES.clear(); CONSUMED_SERVICES.clear(); } + } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerMethodModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerMethodModel.java deleted file mode 100644 index 0798a50029..0000000000 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerMethodModel.java +++ /dev/null @@ -1,161 +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 org.apache.dubbo.rpc.model; - - -import java.lang.reflect.Method; -import java.util.Map; - -import static org.apache.dubbo.rpc.Constants.$INVOKE; - -public class ConsumerMethodModel { - private final Method method; - // private final boolean isCallBack; -// private final boolean isFuture; - private final String[] parameterTypes; - private final Class[] parameterClasses; - private final Class returnClass; - private final String methodName; - private final boolean generic; - - private final AsyncMethodInfo asyncInfo; - - - public ConsumerMethodModel(Method method, Map attributes) { - this.method = method; - this.parameterClasses = method.getParameterTypes(); - this.returnClass = method.getReturnType(); - this.parameterTypes = this.createParamSignature(parameterClasses); - this.methodName = method.getName(); - this.generic = methodName.equals($INVOKE) && parameterTypes != null && parameterTypes.length == 3; - - if (attributes != null) { - asyncInfo = (AsyncMethodInfo) attributes.get(methodName); - } else { - asyncInfo = null; - } - } - - public Method getMethod() { - return method; - } - - public Class getReturnClass() { - return returnClass; - } - - public AsyncMethodInfo getAsyncInfo() { - return asyncInfo; - } - - public String getMethodName() { - return methodName; - } - - public String[] getParameterTypes() { - return parameterTypes; - } - - private String[] createParamSignature(Class[] args) { - if (args == null || args.length == 0) { - return new String[]{}; - } - String[] paramSig = new String[args.length]; - for (int x = 0; x < args.length; x++) { - paramSig[x] = args[x].getName(); - } - return paramSig; - } - - - public boolean isGeneric() { - return generic; - } - - public Class[] getParameterClasses() { - return parameterClasses; - } - - - public static class AsyncMethodInfo { - // callback instance when async-call is invoked - private Object oninvokeInstance; - - // callback method when async-call is invoked - private Method oninvokeMethod; - - // callback instance when async-call is returned - private Object onreturnInstance; - - // callback method when async-call is returned - private Method onreturnMethod; - - // callback instance when async-call has exception thrown - private Object onthrowInstance; - - // callback method when async-call has exception thrown - private Method onthrowMethod; - - public Object getOninvokeInstance() { - return oninvokeInstance; - } - - public void setOninvokeInstance(Object oninvokeInstance) { - this.oninvokeInstance = oninvokeInstance; - } - - public Method getOninvokeMethod() { - return oninvokeMethod; - } - - public void setOninvokeMethod(Method oninvokeMethod) { - this.oninvokeMethod = oninvokeMethod; - } - - public Object getOnreturnInstance() { - return onreturnInstance; - } - - public void setOnreturnInstance(Object onreturnInstance) { - this.onreturnInstance = onreturnInstance; - } - - public Method getOnreturnMethod() { - return onreturnMethod; - } - - public void setOnreturnMethod(Method onreturnMethod) { - this.onreturnMethod = onreturnMethod; - } - - public Object getOnthrowInstance() { - return onthrowInstance; - } - - public void setOnthrowInstance(Object onthrowInstance) { - this.onthrowInstance = onthrowInstance; - } - - public Method getOnthrowMethod() { - return onthrowMethod; - } - - public void setOnthrowMethod(Method onthrowMethod) { - this.onthrowMethod = onthrowMethod; - } - } -} diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java index 4c990a5088..135cadbd7a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java @@ -17,50 +17,49 @@ package org.apache.dubbo.rpc.model; import org.apache.dubbo.common.utils.Assert; +import org.apache.dubbo.common.utils.CollectionUtils; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.IdentityHashMap; -import java.util.List; +import java.util.HashMap; import java.util.Map; -import java.util.Optional; +import java.util.Set; /** - * Consumer Model which is about subscribed services. + * This model is bind to your reference's configuration, for example, group, version or method level configuration. */ public class ConsumerModel { + private final String serviceKey; private final Object proxyObject; - private final String serviceName; - private final Class serviceInterfaceClass; - - private final Map methodModels = new IdentityHashMap(); + private final ServiceModel serviceModel; + private final Map methodConfigs = new HashMap<>(); /** * This constructor create an instance of ConsumerModel and passed objects should not be null. * If service name, service instance, proxy object,methods should not be null. If these are null * then this constructor will throw {@link IllegalArgumentException} - * @param serviceName Name of the service. + * @param serviceKey Name of the service. * @param serviceInterfaceClass Service interface class. * @param proxyObject Proxy object. - * @param methods Methods of service class * @param attributes Attributes of methods. */ - public ConsumerModel(String serviceName + public ConsumerModel(String serviceKey , Class serviceInterfaceClass , Object proxyObject - , Method[] methods + , ServiceModel serviceModel , Map attributes) { - Assert.notEmptyString(serviceName, "Service name can't be null or blank"); + Assert.notEmptyString(serviceKey, "Service name can't be null or blank"); Assert.notNull(serviceInterfaceClass, "Service interface class can't null"); Assert.notNull(proxyObject, "Proxy object can't be null"); - Assert.notNull(methods, "Methods can't be null"); - this.serviceName = serviceName; - this.serviceInterfaceClass = serviceInterfaceClass; + this.serviceKey = serviceKey; this.proxyObject = proxyObject; - for (Method method : methods) { - methodModels.put(method, new ConsumerMethodModel(method, attributes)); + this.serviceModel = serviceModel; + + if (CollectionUtils.isNotEmptyMap(attributes)) { + attributes.forEach((method, object) -> { + methodConfigs.put(method, (AsyncMethodInfo) object); + }); } } @@ -72,41 +71,96 @@ public class ConsumerModel { return proxyObject; } - /** - * Return method model for the given method on consumer side - * - * @param method method object - * @return method model - */ - public ConsumerMethodModel getMethodModel(Method method) { - return methodModels.get(method); - } - - /** - * Return method model for the given method on consumer side - * - * @param method method object - * @return method model - */ - public ConsumerMethodModel getMethodModel(String method) { - Optional> consumerMethodModelEntry = methodModels.entrySet().stream().filter(entry -> entry.getKey().getName().equals(method)).findFirst(); - return consumerMethodModelEntry.map(Map.Entry::getValue).orElse(null); - } - /** * Return all method models for the current service * * @return method model list */ - public List getAllMethods() { - return new ArrayList(methodModels.values()); + public Set getAllMethods() { + return serviceModel.getAllMethods(); } public Class getServiceInterfaceClass() { - return serviceInterfaceClass; + return serviceModel.getServiceInterfaceClass(); } - public String getServiceName() { - return serviceName; + public String getServiceKey() { + return serviceKey; + } + + public AsyncMethodInfo getMethodConfig(String methodName) { + return methodConfigs.get(methodName); + } + + public ServiceModel getServiceModel() { + return serviceModel; + } + + public static class AsyncMethodInfo { + // callback instance when async-call is invoked + private Object oninvokeInstance; + + // callback method when async-call is invoked + private Method oninvokeMethod; + + // callback instance when async-call is returned + private Object onreturnInstance; + + // callback method when async-call is returned + private Method onreturnMethod; + + // callback instance when async-call has exception thrown + private Object onthrowInstance; + + // callback method when async-call has exception thrown + private Method onthrowMethod; + + public Object getOninvokeInstance() { + return oninvokeInstance; + } + + public void setOninvokeInstance(Object oninvokeInstance) { + this.oninvokeInstance = oninvokeInstance; + } + + public Method getOninvokeMethod() { + return oninvokeMethod; + } + + public void setOninvokeMethod(Method oninvokeMethod) { + this.oninvokeMethod = oninvokeMethod; + } + + public Object getOnreturnInstance() { + return onreturnInstance; + } + + public void setOnreturnInstance(Object onreturnInstance) { + this.onreturnInstance = onreturnInstance; + } + + public Method getOnreturnMethod() { + return onreturnMethod; + } + + public void setOnreturnMethod(Method onreturnMethod) { + this.onreturnMethod = onreturnMethod; + } + + public Object getOnthrowInstance() { + return onthrowInstance; + } + + public void setOnthrowInstance(Object onthrowInstance) { + this.onthrowInstance = onthrowInstance; + } + + public Method getOnthrowMethod() { + return onthrowMethod; + } + + public void setOnthrowMethod(Method onthrowMethod) { + this.onthrowMethod = onthrowMethod; + } } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/MethodModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/MethodModel.java new file mode 100644 index 0000000000..58fd2a0939 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/MethodModel.java @@ -0,0 +1,83 @@ +/* + * 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.model; + +import org.apache.dubbo.common.utils.ReflectUtils; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import static org.apache.dubbo.rpc.Constants.$INVOKE; +import static org.apache.dubbo.rpc.Constants.$INVOKE_ASYNC; + +/** + * + */ +public class MethodModel { + private final Method method; + // private final boolean isCallBack; +// private final boolean isFuture; + private final String paramDesc; + private final Class[] parameterClasses; + private final Class returnClass; + private final Type[] returnTypes; + private final String methodName; + private final boolean generic; + + public MethodModel (Method method) { + this.method = method; + this.parameterClasses = method.getParameterTypes(); + this.returnClass = method.getReturnType(); + this.returnTypes = ReflectUtils.getReturnTypes(method); + this.paramDesc = ReflectUtils.getDesc(method); + this.methodName = method.getName(); + this.generic = (methodName.equals($INVOKE) || methodName.equals($INVOKE_ASYNC)) && parameterClasses.length == 3; + } + + public boolean matchParams (String params) { + return paramDesc.equalsIgnoreCase(params); + } + + public Method getMethod() { + return method; + } + + public String getParamDesc() { + return paramDesc; + } + + public Class[] getParameterClasses() { + return parameterClasses; + } + + public Class getReturnClass() { + return returnClass; + } + + public Type[] getReturnTypes() { + return returnTypes; + } + + public String getMethodName() { + return methodName; + } + + public boolean isGeneric() { + return generic; + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderMethodModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderMethodModel.java deleted file mode 100644 index d7b8a9bb87..0000000000 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderMethodModel.java +++ /dev/null @@ -1,63 +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 org.apache.dubbo.rpc.model; - -import java.lang.reflect.Method; - -public class ProviderMethodModel { - private transient final Method method; - private final String methodName; - private final String[] methodArgTypes; - private final String serviceName; - - - public ProviderMethodModel(Method method, String serviceName) { - this.method = method; - this.serviceName = serviceName; - this.methodName = method.getName(); - this.methodArgTypes = getArgTypes(method); - } - - public Method getMethod() { - return method; - } - - public String getMethodName() { - return methodName; - } - - public String[] getMethodArgTypes() { - return methodArgTypes; - } - - public String getServiceName() { - return serviceName; - } - - private static String[] getArgTypes(Method method) { - String[] methodArgTypes = new String[0]; - Class[] parameterTypes = method.getParameterTypes(); - if (parameterTypes.length > 0) { - methodArgTypes = new String[parameterTypes.length]; - int index = 0; - for (Class paramType : parameterTypes) { - methodArgTypes[index++] = paramType.getName(); - } - } - return methodArgTypes; - } -} diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java index 6fb9bebd7e..41f6f7cc63 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java @@ -16,81 +16,43 @@ */ package org.apache.dubbo.rpc.model; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.Set; /** * ProviderModel which is about published services */ public class ProviderModel { - private final String serviceName; + private final String serviceKey; private final Object serviceInstance; - private final Class serviceInterfaceClass; - private final Map> methods = new HashMap>(); + private final ServiceModel serviceModel; - public ProviderModel(String serviceName, Object serviceInstance, Class serviceInterfaceClass) { + public ProviderModel(String serviceKey, Object serviceInstance, ServiceModel serviceModel) { if (null == serviceInstance) { - throw new IllegalArgumentException("Service[" + serviceName + "]Target is NULL."); + throw new IllegalArgumentException("Service[" + serviceKey + "]Target is NULL."); } - this.serviceName = serviceName; + this.serviceKey = serviceKey; this.serviceInstance = serviceInstance; - this.serviceInterfaceClass = serviceInterfaceClass; - - initMethod(); + this.serviceModel = serviceModel; } - - public String getServiceName() { - return serviceName; + public String getServiceKey() { + return serviceKey; } public Class getServiceInterfaceClass() { - return serviceInterfaceClass; + return serviceModel.getServiceInterfaceClass(); } public Object getServiceInstance() { return serviceInstance; } - public List getAllMethods() { - List result = new ArrayList(); - for (List models : methods.values()) { - result.addAll(models); - } - return result; + public Set getAllMethods() { + return serviceModel.getAllMethods(); } - public ProviderMethodModel getMethodModel(String methodName, String[] argTypes) { - List methodModels = methods.get(methodName); - if (methodModels != null) { - for (ProviderMethodModel methodModel : methodModels) { - if (Arrays.equals(argTypes, methodModel.getMethodArgTypes())) { - return methodModel; - } - } - } - return null; + public ServiceModel getServiceModel() { + return serviceModel; } - - private void initMethod() { - Method[] methodsToExport = null; - methodsToExport = this.serviceInterfaceClass.getMethods(); - - for (Method method : methodsToExport) { - method.setAccessible(true); - - List methodModels = methods.get(method.getName()); - if (methodModels == null) { - methodModels = new ArrayList(1); - methods.put(method.getName(), methodModels); - } - methodModels.add(new ProviderMethodModel(method, serviceName)); - } - } - } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java new file mode 100644 index 0000000000..94e0ad223d --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java @@ -0,0 +1,100 @@ +/* + * 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.model; + +import org.apache.dubbo.common.utils.CollectionUtils; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +public class ServiceModel { + private final String serviceName; + private final Class serviceInterfaceClass; + // to accelarate search + private final Map> methods = new HashMap<>(); + private final Map> descToMethods = new HashMap<>(); + + public ServiceModel (Class interfaceClass) { + this.serviceInterfaceClass = interfaceClass; + this.serviceName = interfaceClass.getName(); + initMethods(); + } + + private void initMethods() { + Method[] methodsToExport = null; + methodsToExport = this.serviceInterfaceClass.getMethods(); + + for (Method method : methodsToExport) { + method.setAccessible(true); + + Set methodModels = methods.computeIfAbsent(method.getName(), (k) ->new HashSet<>(1)); + methodModels.add(new MethodModel(method)); + } + + methods.forEach((methodName, methodList) -> { + Map descMap = descToMethods.computeIfAbsent(methodName, k -> new HashMap<>()); + methodList.forEach(methodModel -> descMap.put(methodModel.getParamDesc(), methodModel)); + +// Map[], MethodModel> typesMap = typeToMethods.computeIfAbsent(methodName, k -> new HashMap<>()); +// methodList.forEach(methodModel -> typesMap.put(methodModel.getParameterClasses(), methodModel)); + }); + } + + public String getServiceName() { + return serviceName; + } + + public Class getServiceInterfaceClass() { + return serviceInterfaceClass; + } + + public Set getAllMethods () { + Set methodModels = new HashSet<>(); + methods.forEach((k, v) -> methodModels.addAll(v)); + return methodModels; + } + + public Optional getMethod (String methodName, String params) { + Map methods = descToMethods.get(methodName); + if (CollectionUtils.isNotEmptyMap(methods)) { + return Optional.ofNullable(methods.get(params)); + } + return Optional.empty(); + } + + public Optional getMethod (String methodName, Class[] paramTypes) { + Set methodModels = methods.get(methodName); + if (CollectionUtils.isNotEmpty(methodModels)) { + for (MethodModel methodModel : methodModels) { + if (Arrays.equals(paramTypes, methodModel.getParameterClasses())) { + return Optional.of(methodModel); + } + } + } + return Optional.empty(); + } + + public Set getMethods (String methodName) { + return methods.get(methodName); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java index fe42fb2c6b..4008c447ba 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java @@ -27,7 +27,6 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.CompletableFuture; @@ -112,10 +111,7 @@ public abstract class AbstractProxyInvoker implements Invoker { private CompletableFuture wrapWithFuture (Object value, Invocation invocation) { if (RpcContext.getContext().isAsyncStarted()) { return ((AsyncContextImpl)(RpcContext.getContext().getAsyncContext())).getInternalFuture(); - } else if (RpcUtils.isReturnTypeFuture(invocation)) { - if (value == null) { - return CompletableFuture.completedFuture(null); - } + } else if (value instanceof CompletableFuture) { return (CompletableFuture) value; } return CompletableFuture.completedFuture(value); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java index 1d047cdccf..9cd1f27ca2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java @@ -52,6 +52,6 @@ public class InvokerInvocationHandler implements InvocationHandler { return invoker.equals(args[0]); } - return invoker.invoke(new RpcInvocation(method, args)).recreate(); + return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args)).recreate(); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java index 955cb31f98..2d70a9ed8e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java @@ -27,8 +27,6 @@ import org.apache.dubbo.rpc.RpcInvocation; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicLong; @@ -36,7 +34,6 @@ import static org.apache.dubbo.rpc.Constants.$INVOKE; import static org.apache.dubbo.rpc.Constants.$INVOKE_ASYNC; import static org.apache.dubbo.rpc.Constants.ASYNC_KEY; import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; -import static org.apache.dubbo.rpc.Constants.FUTURE_GENERATED_KEY; import static org.apache.dubbo.rpc.Constants.ID_KEY; import static org.apache.dubbo.rpc.Constants.RETURN_KEY; /** @@ -171,7 +168,12 @@ public class RpcUtils { } public static boolean isReturnTypeFuture(Invocation inv) { - Class clazz = getReturnType(inv); + Class clazz; + if (inv instanceof RpcInvocation) { + clazz = ((RpcInvocation) inv).getReturnType(); + } else { + clazz = getReturnType(inv); + } return (clazz != null && CompletableFuture.class.isAssignableFrom(clazz)) || isGenericAsync(inv); } @@ -198,12 +200,4 @@ public class RpcUtils { } return isOneway; } - - public static Map getNecessaryAttachments(Invocation inv) { - Map attachments = new HashMap<>(inv.getAttachments()); - attachments.remove(ASYNC_KEY); - attachments.remove(FUTURE_GENERATED_KEY); - return attachments; - } - } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java index bc9c132037..9b8ed5d7a2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java @@ -28,7 +28,6 @@ import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.LocalException; import com.alibaba.com.caucho.hessian.HessianException; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -52,7 +51,7 @@ public class ExceptionFilterTest { RpcException exception = new RpcException("TestRpcException"); ExceptionFilter exceptionFilter = new ExceptionFilter(); - RpcInvocation invocation = new RpcInvocation("sayHello", new Class[]{String.class}, new Object[]{"world"}); + RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"world"}); Invoker invoker = mock(Invoker.class); given(invoker.getInterface()).willReturn(DemoService.class); given(invoker.invoke(eq(invocation))).willThrow(exception); @@ -76,7 +75,7 @@ public class ExceptionFilterTest { public void testJavaException() { ExceptionFilter exceptionFilter = new ExceptionFilter(); - RpcInvocation invocation = new RpcInvocation("sayHello", new Class[]{String.class}, new Object[]{"world"}); + RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"world"}); AppResponse appResponse = new AppResponse(); appResponse.setException(new IllegalArgumentException("java")); @@ -96,7 +95,7 @@ public class ExceptionFilterTest { public void testRuntimeException() { ExceptionFilter exceptionFilter = new ExceptionFilter(); - RpcInvocation invocation = new RpcInvocation("sayHello", new Class[]{String.class}, new Object[]{"world"}); + RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"world"}); AppResponse appResponse = new AppResponse(); appResponse.setException(new LocalException("localException")); @@ -116,7 +115,7 @@ public class ExceptionFilterTest { public void testConvertToRunTimeException() throws Exception { ExceptionFilter exceptionFilter = new ExceptionFilter(); - RpcInvocation invocation = new RpcInvocation("sayHello", new Class[]{String.class}, new Object[]{"world"}); + RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"world"}); AppResponse mockRpcResult = new AppResponse(); mockRpcResult.setException(new HessianException("hessian")); diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java index b571bd1de3..f3702673e2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java @@ -36,11 +36,11 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.rpc.Constants.$INVOKE; +import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; +import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.apache.dubbo.rpc.Constants.$INVOKE; -import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA; -import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; public class GenericFilterTest { GenericFilter genericFilter = new GenericFilter(); @@ -54,7 +54,7 @@ public class GenericFilterTest { person.put("name", "dubbo"); person.put("age", 10); - RpcInvocation invocation = new RpcInvocation($INVOKE, genericInvoke.getParameterTypes(), + RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), genericInvoke.getParameterTypes(), new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + @@ -82,7 +82,7 @@ public class GenericFilterTest { person.put("name", "dubbo"); person.put("age", 10); - RpcInvocation invocation = new RpcInvocation($INVOKE, genericInvoke.getParameterTypes(), + RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), genericInvoke.getParameterTypes(), new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); invocation.setAttachment(GENERIC_KEY, GENERIC_SERIALIZATION_NATIVE_JAVA); @@ -106,7 +106,7 @@ public class GenericFilterTest { person.put("name", "dubbo"); person.put("age", 10); - RpcInvocation invocation = new RpcInvocation("sayHi", genericInvoke.getParameterTypes() + RpcInvocation invocation = new RpcInvocation("sayHi", GenericService.class.getName(), genericInvoke.getParameterTypes() , new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + @@ -130,7 +130,7 @@ public class GenericFilterTest { person.put("name", "dubbo"); person.put("age", 10); - RpcInvocation invocation = new RpcInvocation($INVOKE, genericInvoke.getParameterTypes() + RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), genericInvoke.getParameterTypes() , new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java index 7145aa08ab..0d6e9fa406 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java @@ -36,11 +36,10 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.when; - import static org.apache.dubbo.rpc.Constants.$INVOKE; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; public class GenericImplFilterTest { @@ -49,7 +48,7 @@ public class GenericImplFilterTest { @Test public void testInvoke() throws Exception { - RpcInvocation invocation = new RpcInvocation("getPerson", + RpcInvocation invocation = new RpcInvocation("getPerson", "org.apache.dubbo.rpc.support.DemoService", new Class[]{Person.class}, new Object[]{new Person("dubbo", 10)}); @@ -77,7 +76,7 @@ public class GenericImplFilterTest { @Test public void testInvokeWithException() throws Exception { - RpcInvocation invocation = new RpcInvocation("getPerson", + RpcInvocation invocation = new RpcInvocation("getPerson", "org.apache.dubbo.rpc.support.DemoService", new Class[]{Person.class}, new Object[]{new Person("dubbo", 10)}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + @@ -105,7 +104,7 @@ public class GenericImplFilterTest { person.put("name", "dubbo"); person.put("age", 10); - RpcInvocation invocation = new RpcInvocation($INVOKE, genericInvoke.getParameterTypes(), + RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), genericInvoke.getParameterTypes(), new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java index 1bd288f12f..1abaf0e821 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java @@ -51,7 +51,7 @@ public abstract class AbstractProxyTest { //Assertions.assertEquals(proxy.toString(), invoker.toString()); //Assertions.assertEquals(proxy.hashCode(), invoker.hashCode()); - Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", new Class[]{String.class}, new Object[]{"aa"})).getValue() + Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"aa"})).getValue() , proxy.echo("aa")); } @@ -65,7 +65,7 @@ public abstract class AbstractProxyTest { Assertions.assertEquals(invoker.getInterface(), DemoService.class); - Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", new Class[]{String.class}, new Object[]{"aa"})).getValue(), + Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", DemoService.class.getName(), new Class[]{String.class}, new Object[]{"aa"})).getValue(), origin.echo("aa")); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java index e479445ba6..ec5b2abdf2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java @@ -38,6 +38,11 @@ public class MockInvocation implements Invocation { return "echo"; } + @Override + public String getServiceName() { + return "DemoService"; + } + public Class[] getParameterTypes() { return new Class[]{String.class}; } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java index 6a326c295a..6e75a541d4 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -28,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -35,8 +37,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; - public class RpcUtilsTest { /** @@ -48,7 +48,7 @@ public class RpcUtilsTest { URL url = URL.valueOf("dubbo://localhost/?test.async=true"); Map attachments = new HashMap(); attachments.put("aa", "bb"); - Invocation inv = new RpcInvocation("test", new Class[]{}, new String[]{}, attachments); + Invocation inv = new RpcInvocation("test", "DemoService", new Class[]{}, new String[]{}, attachments); RpcUtils.attachInvocationIdIfAsync(url, inv); long id1 = RpcUtils.getInvocationId(inv); RpcUtils.attachInvocationIdIfAsync(url, inv); @@ -65,7 +65,7 @@ public class RpcUtilsTest { @Test public void testAttachInvocationIdIfAsync_sync() { URL url = URL.valueOf("dubbo://localhost/"); - Invocation inv = new RpcInvocation("test", new Class[]{}, new String[]{}); + Invocation inv = new RpcInvocation("test", "DemoService", new Class[]{}, new String[]{}); RpcUtils.attachInvocationIdIfAsync(url, inv); assertNull(RpcUtils.getInvocationId(inv)); } @@ -77,7 +77,7 @@ public class RpcUtilsTest { @Test public void testAttachInvocationIdIfAsync_nullAttachments() { URL url = URL.valueOf("dubbo://localhost/?test.async=true"); - Invocation inv = new RpcInvocation("test", new Class[]{}, new String[]{}); + Invocation inv = new RpcInvocation("test", "DemoService", new Class[]{}, new String[]{}); RpcUtils.attachInvocationIdIfAsync(url, inv); assertTrue(RpcUtils.getInvocationId(inv) >= 0l); } @@ -89,7 +89,7 @@ public class RpcUtilsTest { @Test public void testAttachInvocationIdIfAsync_forceNotAttache() { URL url = URL.valueOf("dubbo://localhost/?test.async=true&" + AUTO_ATTACH_INVOCATIONID_KEY + "=false"); - Invocation inv = new RpcInvocation("test", new Class[]{}, new String[]{}); + Invocation inv = new RpcInvocation("test", "DemoService", new Class[]{}, new String[]{}); RpcUtils.attachInvocationIdIfAsync(url, inv); assertNull(RpcUtils.getInvocationId(inv)); } @@ -101,7 +101,7 @@ public class RpcUtilsTest { @Test public void testAttachInvocationIdIfAsync_forceAttache() { URL url = URL.valueOf("dubbo://localhost/?" + AUTO_ATTACH_INVOCATIONID_KEY + "=true"); - Invocation inv = new RpcInvocation("test", new Class[]{}, new String[]{}); + Invocation inv = new RpcInvocation("test", "DemoService", new Class[]{}, new String[]{}); RpcUtils.attachInvocationIdIfAsync(url, inv); assertNotNull(RpcUtils.getInvocationId(inv)); } @@ -109,40 +109,41 @@ public class RpcUtilsTest { @Test public void testGetReturnTypes() throws Exception { Invoker invoker = mock(Invoker.class); + String service = "org.apache.dubbo.rpc.support.DemoService"; given(invoker.getUrl()).willReturn(URL.valueOf("test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService")); - Invocation inv = new RpcInvocation("testReturnType", new Class[]{String.class}, null, null, invoker); + Invocation inv = new RpcInvocation("testReturnType", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types = RpcUtils.getReturnTypes(inv); Assertions.assertEquals(2, types.length); Assertions.assertEquals(String.class, types[0]); Assertions.assertEquals(String.class, types[1]); - Invocation inv1 = new RpcInvocation("testReturnType1", new Class[]{String.class}, null, null, invoker); + Invocation inv1 = new RpcInvocation("testReturnType1", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types1 = RpcUtils.getReturnTypes(inv1); Assertions.assertEquals(2, types1.length); Assertions.assertEquals(List.class, types1[0]); Assertions.assertEquals(DemoService.class.getMethod("testReturnType1", new Class[]{String.class}).getGenericReturnType(), types1[1]); - Invocation inv2 = new RpcInvocation("testReturnType2", new Class[]{String.class}, null, null, invoker); + Invocation inv2 = new RpcInvocation("testReturnType2", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types2 = RpcUtils.getReturnTypes(inv2); Assertions.assertEquals(2, types2.length); Assertions.assertEquals(String.class, types2[0]); Assertions.assertEquals(String.class, types2[1]); - Invocation inv3 = new RpcInvocation("testReturnType3", new Class[]{String.class}, null, null, invoker); + Invocation inv3 = new RpcInvocation("testReturnType3", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types3 = RpcUtils.getReturnTypes(inv3); Assertions.assertEquals(2, types3.length); Assertions.assertEquals(List.class, types3[0]); java.lang.reflect.Type genericReturnType3 = DemoService.class.getMethod("testReturnType3", new Class[]{String.class}).getGenericReturnType(); Assertions.assertEquals(((ParameterizedType) genericReturnType3).getActualTypeArguments()[0], types3[1]); - Invocation inv4 = new RpcInvocation("testReturnType4", new Class[]{String.class}, null, null, invoker); + Invocation inv4 = new RpcInvocation("testReturnType4", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types4 = RpcUtils.getReturnTypes(inv4); Assertions.assertEquals(2, types4.length); Assertions.assertNull(types4[0]); Assertions.assertNull(types4[1]); - Invocation inv5 = new RpcInvocation("testReturnType5", new Class[]{String.class}, null, null, invoker); + Invocation inv5 = new RpcInvocation("testReturnType5", service, new Class[]{String.class}, null, null, invoker); java.lang.reflect.Type[] types5 = RpcUtils.getReturnTypes(inv5); Assertions.assertEquals(2, types5.length); Assertions.assertEquals(Map.class, types5[0]); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index 69a0629c4e..6d0d995222 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -22,7 +22,6 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.serialize.Cleanable; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.utils.Assert; -import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; @@ -30,17 +29,21 @@ import org.apache.dubbo.remoting.Decodeable; import org.apache.dubbo.remoting.exchange.Request; import org.apache.dubbo.remoting.transport.CodecSupport; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.MethodModel; +import org.apache.dubbo.rpc.model.ServiceModel; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument; import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; +import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument; public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable { @@ -97,27 +100,37 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec request.setVersion(dubboVersion); setAttachment(DUBBO_VERSION_KEY, dubboVersion); - setAttachment(PATH_KEY, in.readUTF()); + String path = in.readUTF(); + setAttachment(PATH_KEY, path); setAttachment(VERSION_KEY, in.readUTF()); setMethodName(in.readUTF()); + + String desc = in.readUTF(); + setParameterTypesDesc(desc); + try { - Object[] args; - Class[] pts; - String desc = in.readUTF(); - if (desc.length() == 0) { - pts = DubboCodec.EMPTY_CLASS_ARRAY; - args = DubboCodec.EMPTY_OBJECT_ARRAY; - } else { - pts = ReflectUtils.desc2classArray(desc); - args = new Object[pts.length]; - for (int i = 0; i < args.length; i++) { - try { - args[i] = in.readObject(pts[i]); - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("Decode argument failed: " + e.getMessage(), e); + Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY; + Class[] pts = DubboCodec.EMPTY_CLASS_ARRAY; + if (desc.length() > 0) { + // TODO, lambda function requires variables to be final. + Optional serviceModel = ApplicationModel.getServiceModel(path); + if (serviceModel.isPresent()) { + Optional methodOptional = serviceModel.get().getMethod(getMethodName(), desc); + if (methodOptional.isPresent()) { + pts = methodOptional.get().getParameterClasses(); + args = new Object[pts.length]; + for (int i = 0; i < args.length; i++) { + try { + args[i] = in.readObject(pts[i]); + } catch (Exception e) { + if (log.isWarnEnabled()) { + log.warn("Decode argument failed: " + e.getMessage(), e); + } + } } + + this.setReturnTypes(methodOptional.get().getReturnTypes()); } } } @@ -132,6 +145,7 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec attachment.putAll(map); setAttachments(attachment); } + //decode argument ,may be callback for (int i = 0; i < args.length; i++) { args[i] = decodeInvocationArgument(channel, this, pts, i, args[i]); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java index 9515a1ba51..1a2347c07a 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java @@ -30,6 +30,7 @@ import org.apache.dubbo.remoting.exchange.Response; import org.apache.dubbo.remoting.transport.CodecSupport; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; @@ -38,6 +39,7 @@ import java.io.OutputStream; import java.lang.reflect.Type; import java.util.Map; + public class DecodeableRpcResult extends AppResponse implements Codec, Decodeable { private static final Logger log = LoggerFactory.getLogger(DecodeableRpcResult.class); @@ -124,7 +126,12 @@ public class DecodeableRpcResult extends AppResponse implements Codec, Decodeabl private void handleValue(ObjectInput in) throws IOException { try { - Type[] returnTypes = RpcUtils.getReturnTypes(invocation); + Type[] returnTypes; + if (invocation instanceof RpcInvocation) { + returnTypes = ((RpcInvocation)invocation).getReturnTypes(); + } else { + returnTypes = RpcUtils.getReturnTypes(invocation); + } Object value = null; if (ArrayUtils.isEmpty(returnTypes)) { value = in.readObject(); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index dd3e847748..c4a165809a 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -23,7 +23,6 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; -import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.exchange.Request; @@ -33,17 +32,16 @@ import org.apache.dubbo.remoting.transport.CodecSupport; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; import java.io.InputStream; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DECODE_IN_IO_THREAD_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD; -import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; /** * Dubbo codec. @@ -179,14 +177,14 @@ public class DubboCodec extends ExchangeCodec { out.writeUTF(inv.getAttachment(VERSION_KEY)); out.writeUTF(inv.getMethodName()); - out.writeUTF(ReflectUtils.getDesc(inv.getParameterTypes())); + out.writeUTF(inv.getParameterTypesDesc()); Object[] args = inv.getArguments(); if (args != null) { for (int i = 0; i < args.length; i++) { out.writeObject(encodeInvocationArgument(channel, inv, i)); } } - out.writeObject(RpcUtils.getNecessaryAttachments(inv)); + out.writeObject(inv.getAttachments()); } @Override diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java index 3cc20237f3..ae52a671fc 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java @@ -62,27 +62,27 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.rpc.Constants.LAZY_CONNECT_KEY; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ON_CONNECT_KEY; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ON_DISCONNECT_KEY; -import static org.apache.dubbo.remoting.Constants.DEFAULT_HEARTBEAT; -import static org.apache.dubbo.remoting.Constants.HEARTBEAT_KEY; import static org.apache.dubbo.remoting.Constants.CHANNEL_READONLYEVENT_SENT_KEY; import static org.apache.dubbo.remoting.Constants.CLIENT_KEY; import static org.apache.dubbo.remoting.Constants.CODEC_KEY; +import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY; +import static org.apache.dubbo.remoting.Constants.DEFAULT_HEARTBEAT; import static org.apache.dubbo.remoting.Constants.DEFAULT_REMOTING_CLIENT; +import static org.apache.dubbo.remoting.Constants.HEARTBEAT_KEY; import static org.apache.dubbo.remoting.Constants.SERVER_KEY; import static org.apache.dubbo.rpc.Constants.DEFAULT_REMOTING_SERVER; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY; -import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY; import static org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.IS_CALLBACK_SERVICE; import static org.apache.dubbo.rpc.Constants.IS_SERVER_KEY; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.OPTIMIZER_KEY; +import static org.apache.dubbo.rpc.Constants.LAZY_CONNECT_KEY; import static org.apache.dubbo.rpc.Constants.STUB_EVENT_KEY; import static org.apache.dubbo.rpc.Constants.STUB_EVENT_METHODS_KEY; -import static org.apache.dubbo.rpc.protocol.dubbo.Constants.SHARE_CONNECTIONS_KEY; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_SHARE_CONNECTIONS; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.IS_CALLBACK_SERVICE; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ON_CONNECT_KEY; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ON_DISCONNECT_KEY; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.OPTIMIZER_KEY; +import static org.apache.dubbo.rpc.protocol.dubbo.Constants.SHARE_CONNECTIONS_KEY; /** @@ -187,13 +187,22 @@ public class DubboProtocol extends AbstractProtocol { } } + /** + * FIXME channel.getUrl() always binds to a fixed service, and this service is random. + * we can choose to use a common service to carry onConnect event if there's no easy way to get the specific + * service this connection is binding to. + * @param channel + * @param url + * @param methodKey + * @return + */ private Invocation createInvocation(Channel channel, URL url, String methodKey) { String method = url.getParameter(methodKey); if (method == null || method.length() == 0) { return null; } - RpcInvocation invocation = new RpcInvocation(method, new Class[0], new Object[0]); + RpcInvocation invocation = new RpcInvocation(method, url.getParameter(INTERFACE_KEY), new Class[0], new Object[0]); invocation.setAttachment(PATH_KEY, url.getPath()); invocation.setAttachment(GROUP_KEY, url.getParameter(GROUP_KEY)); invocation.setAttachment(INTERFACE_KEY, url.getParameter(INTERFACE_KEY)); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java index dcf732e2e5..5d34270a86 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java @@ -26,7 +26,6 @@ import org.apache.dubbo.rpc.ListenableFilter; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.model.ConsumerModel; import java.lang.reflect.InvocationTargetException; @@ -55,7 +54,7 @@ public class FutureFilter extends ListenableFilter { } private void fireInvokeCallback(final Invoker invoker, final Invocation invocation) { - final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); + final ConsumerModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); if (asyncMethodInfo == null) { return; } @@ -83,7 +82,7 @@ public class FutureFilter extends ListenableFilter { } private void fireReturnCallback(final Invoker invoker, final Invocation invocation, final Object result) { - final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); + final ConsumerModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); if (asyncMethodInfo == null) { return; } @@ -129,7 +128,7 @@ public class FutureFilter extends ListenableFilter { } private void fireThrowCallback(final Invoker invoker, final Invocation invocation, final Throwable exception) { - final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); + final ConsumerModel.AsyncMethodInfo asyncMethodInfo = getAsyncMethodInfo(invoker, invocation); if (asyncMethodInfo == null) { return; } @@ -175,7 +174,7 @@ public class FutureFilter extends ListenableFilter { } } - private ConsumerMethodModel.AsyncMethodInfo getAsyncMethodInfo(Invoker invoker, Invocation invocation) { + private ConsumerModel.AsyncMethodInfo getAsyncMethodInfo(Invoker invoker, Invocation invocation) { final ConsumerModel consumerModel = ApplicationModel.getConsumerModel(invoker.getUrl().getServiceKey()); if (consumerModel == null) { return null; @@ -186,12 +185,7 @@ public class FutureFilter extends ListenableFilter { methodName = (String) invocation.getArguments()[0]; } - ConsumerMethodModel methodModel = consumerModel.getMethodModel(methodName); - if (methodModel == null) { - return null; - } - - final ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = methodModel.getAsyncInfo(); + final ConsumerModel.AsyncMethodInfo asyncMethodInfo = consumerModel.getMethodConfig(methodName); if (asyncMethodInfo == null) { return null; } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java index 3998026b70..1534bb2ee5 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java @@ -25,7 +25,7 @@ import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.telnet.support.Help; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.ProviderMethodModel; +import org.apache.dubbo.rpc.model.MethodModel; import org.apache.dubbo.rpc.model.ProviderModel; import com.alibaba.fastjson.JSON; @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import static org.apache.dubbo.common.utils.PojoUtils.realize; @@ -152,15 +153,15 @@ public class InvokeTelnetHandler implements TelnetHandler { private boolean isServiceMatch(String service, ProviderModel provider) { - return provider.getServiceName().equalsIgnoreCase(service) + return provider.getServiceKey().equalsIgnoreCase(service) || provider.getServiceInterfaceClass().getSimpleName().equalsIgnoreCase(service) || provider.getServiceInterfaceClass().getName().equalsIgnoreCase(service) || StringUtils.isEmpty(service); } - private List findSameSignatureMethod(List methods, String lookupMethodName, List args) { + private List findSameSignatureMethod(Set methods, String lookupMethodName, List args) { List sameSignatureMethods = new ArrayList<>(); - for (ProviderMethodModel model : methods) { + for (MethodModel model : methods) { Method method = model.getMethod(); if (method.getName().equals(lookupMethodName) && method.getParameterTypes().length == args.size()) { sameSignatureMethods.add(method); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java index 0eaf1a22d0..f0953ea627 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandler.java @@ -23,9 +23,8 @@ import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.telnet.support.Help; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.model.ConsumerModel; -import org.apache.dubbo.rpc.model.ProviderMethodModel; +import org.apache.dubbo.rpc.model.MethodModel; import org.apache.dubbo.rpc.model.ProviderModel; import java.lang.reflect.Method; @@ -87,11 +86,11 @@ public class ListTelnetHandler implements TelnetHandler { } for (ProviderModel provider : ApplicationModel.allProviderModels()) { - buf.append(provider.getServiceName()); + buf.append(provider.getServiceKey()); if (detail) { buf.append(" -> "); buf.append(" published: "); - buf.append(isRegistered(provider.getServiceName()) ? "Y" : "N"); + buf.append(isRegistered(provider.getServiceKey()) ? "Y" : "N"); } buf.append("\r\n"); } @@ -103,11 +102,11 @@ public class ListTelnetHandler implements TelnetHandler { } for (ConsumerModel consumer : ApplicationModel.allConsumerModels()) { - buf.append(consumer.getServiceName()); + buf.append(consumer.getServiceKey()); if (detail) { buf.append(" -> "); buf.append(" addresses: "); - buf.append(getConsumerAddressNum(consumer.getServiceName())); + buf.append(getConsumerAddressNum(consumer.getServiceKey())); } } } @@ -120,8 +119,8 @@ public class ListTelnetHandler implements TelnetHandler { private void printSpecifiedProvidedService(String service, StringBuilder buf, boolean detail) { for (ProviderModel provider : ApplicationModel.allProviderModels()) { if (isProviderMatched(service,provider)) { - buf.append(provider.getServiceName()).append(" (as provider):\r\n"); - for (ProviderMethodModel method : provider.getAllMethods()) { + buf.append(provider.getServiceKey()).append(" (as provider):\r\n"); + for (MethodModel method : provider.getAllMethods()) { printMethod(method.getMethod(), buf, detail); } } @@ -131,8 +130,8 @@ public class ListTelnetHandler implements TelnetHandler { private void printSpecifiedReferredService(String service, StringBuilder buf, boolean detail) { for (ConsumerModel consumer : ApplicationModel.allConsumerModels()) { if (isConsumerMatcher(service,consumer)) { - buf.append(consumer.getServiceName()).append(" (as consumer):\r\n"); - for (ConsumerMethodModel method : consumer.getAllMethods()) { + buf.append(consumer.getServiceKey()).append(" (as consumer):\r\n"); + for (MethodModel method : consumer.getAllMethods()) { printMethod(method.getMethod(), buf, detail); } } @@ -149,13 +148,13 @@ public class ListTelnetHandler implements TelnetHandler { } private boolean isProviderMatched(String service, ProviderModel provider) { - return service.equalsIgnoreCase(provider.getServiceName()) + return service.equalsIgnoreCase(provider.getServiceKey()) || service.equalsIgnoreCase(provider.getServiceInterfaceClass().getName()) || service.equalsIgnoreCase(provider.getServiceInterfaceClass().getSimpleName()); } private boolean isConsumerMatcher(String service,ConsumerModel consumer) { - return service.equalsIgnoreCase(consumer.getServiceName()) + return service.equalsIgnoreCase(consumer.getServiceKey()) || service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getName()) || service.equalsIgnoreCase(consumer.getServiceInterfaceClass().getSimpleName()); } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ImplicitCallBackTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ImplicitCallBackTest.java index 5085a447cf..ffc175fd21 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ImplicitCallBackTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ImplicitCallBackTest.java @@ -23,7 +23,6 @@ import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils; @@ -108,31 +107,31 @@ public class ImplicitCallBackTest { public void initImplicitCallBackURL_onlyOnthrow() throws Exception { Map attitudes = new HashMap<>(); - ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = new ConsumerMethodModel.AsyncMethodInfo(); + ConsumerModel.AsyncMethodInfo asyncMethodInfo = new ConsumerModel.AsyncMethodInfo(); asyncMethodInfo.setOnthrowInstance(notify); asyncMethodInfo.setOnthrowMethod(onThrowMethod); attitudes.put("get", asyncMethodInfo); - ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, IDemoService.class.getMethods(), attitudes)); + ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, ApplicationModel.registerServiceModel(IDemoService.class), attitudes)); } //================================================================================================ public void initImplicitCallBackURL_onlyOnreturn() throws Exception { Map attitudes = new HashMap<>(); - ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = new ConsumerMethodModel.AsyncMethodInfo(); + ConsumerModel.AsyncMethodInfo asyncMethodInfo = new ConsumerModel.AsyncMethodInfo(); asyncMethodInfo.setOnreturnInstance(notify); asyncMethodInfo.setOnreturnMethod(onReturnMethod); attitudes.put("get", asyncMethodInfo); - ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, IDemoService.class.getMethods(), attitudes)); + ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, ApplicationModel.registerServiceModel(IDemoService.class), attitudes)); } public void initImplicitCallBackURL_onlyOninvoke() throws Exception { Map attitudes = new HashMap<>(); - ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = new ConsumerMethodModel.AsyncMethodInfo(); + ConsumerModel.AsyncMethodInfo asyncMethodInfo = new ConsumerModel.AsyncMethodInfo(); asyncMethodInfo.setOninvokeInstance(notify); asyncMethodInfo.setOninvokeMethod(onInvokeMethod); attitudes.put("get", asyncMethodInfo); - ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, IDemoService.class.getMethods(), attitudes)); + ApplicationModel.initConsumerModel(consumerUrl.getServiceKey(), new ConsumerModel(consumerUrl.getServiceKey(), IDemoService.class, demoProxy, ApplicationModel.registerServiceModel(IDemoService.class), attitudes)); } @Test diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokerTelnetHandlerTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokerTelnetHandlerTest.java index 4512d29a6a..e14b5dc023 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokerTelnetHandlerTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokerTelnetHandlerTest.java @@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService; import org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl; import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -68,7 +69,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = invoke.telnet(mockChannel, "echo(\"ok\")"); @@ -83,7 +84,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")"); @@ -98,7 +99,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); try { invoke.telnet(mockChannel, "sayHello(null)"); @@ -114,7 +115,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = invoke.telnet(mockChannel, "getType(\"High\")"); @@ -130,7 +131,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = invoke.telnet(mockChannel, "getPerson({\"name\":\"zhangsan\",\"age\":12,\"class\":\"org.apache.dubbo.rpc.protocol.dubbo.support.Person\"})"); assertTrue(result.contains("result: 12")); @@ -144,7 +145,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String param = "{\"name\":\"Dubbo\",\"age\":8}"; String result = invoke.telnet(mockChannel, "getPerson(" + param + ")"); @@ -161,7 +162,7 @@ public class InvokerTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String param = "{\"name\":\"Dubbo\",\"age\":8},{\"name\":\"Apache\",\"age\":20}"; String result = invoke.telnet(mockChannel, "getPerson(" + param + ")"); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandlerTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandlerTest.java index 23306a5c64..420cbd4676 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandlerTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ListTelnetHandlerTest.java @@ -27,8 +27,8 @@ import org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl; import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.lang.reflect.Method; @@ -66,7 +66,7 @@ public class ListTelnetHandlerTest { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService"); - ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", providerModel); String result = list.telnet(mockChannel, "-l DemoService"); @@ -80,7 +80,7 @@ public class ListTelnetHandlerTest { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService"); - ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", providerModel); String result = list.telnet(mockChannel, "DemoService"); @@ -94,7 +94,7 @@ public class ListTelnetHandlerTest { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn(null); - ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", providerModel); String result = list.telnet(mockChannel, ""); @@ -106,7 +106,7 @@ public class ListTelnetHandlerTest { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn(null); - ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", providerModel); String result = list.telnet(mockChannel, "-l"); @@ -118,7 +118,7 @@ public class ListTelnetHandlerTest { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService"); - ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", providerModel); String result = list.telnet(mockChannel, ""); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/SelectTelnetHandlerTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/SelectTelnetHandlerTest.java index df8bf470ad..fbff17bc53 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/SelectTelnetHandlerTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/SelectTelnetHandlerTest.java @@ -25,6 +25,7 @@ import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService; import org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl; import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -71,7 +72,7 @@ public class SelectTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = select.telnet(mockChannel, "1"); @@ -86,7 +87,7 @@ public class SelectTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = select.telnet(mockChannel, "index"); @@ -107,7 +108,7 @@ public class SelectTelnetHandlerTest { given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); - ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + ProviderModel providerModel = new ProviderModel(DemoService.class.getName(), new DemoServiceImpl(), ApplicationModel.registerServiceModel(DemoService.class)); ApplicationModel.initProviderModel(DemoService.class.getName(), providerModel); String result = select.telnet(mockChannel, null); diff --git a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java index a1682af280..f3d77af865 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/RestProtocolTest.java @@ -36,11 +36,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.apache.dubbo.remoting.Constants.SERVER_KEY; +import static org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY; - public class RestProtocolTest { private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("rest"); private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); @@ -163,7 +162,7 @@ public class RestProtocolTest { Exporter exporter = protocol.export(proxy.getInvoker(server, DemoService.class, exportUrl)); - RpcInvocation rpcInvocation = new RpcInvocation("hello", new Class[]{Integer.class, Integer.class}, new Integer[]{2, 3}); + RpcInvocation rpcInvocation = new RpcInvocation("hello", DemoService.class.getName(), new Class[]{Integer.class, Integer.class}, new Integer[]{2, 3}); Result result = exporter.getInvoker().invoke(rpcInvocation); assertThat(result.getValue(), CoreMatchers.is(5));