This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0-multi-instances
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 945e903ab471b3d707f426b5db7988ef8b4a6ad2
Author: Albumen Kevin <[email protected]>
AuthorDate: Mon Aug 30 10:49:50 2021 +0800

    Invocation pass ServiceModel
---
 .../rpc/cluster/directory/MockDirInvocation.java   |  6 ++
 .../src/main/java/org/apache/dubbo/common/URL.java | 14 ++++-
 .../dubbo/common/constants/CommonConstants.java    |  2 +
 .../java/com/alibaba/dubbo/rpc/Invocation.java     | 12 ++++
 .../org/apache/dubbo/service/MockInvocation.java   |  6 ++
 .../main/java/org/apache/dubbo/rpc/Invocation.java |  3 +
 .../java/org/apache/dubbo/rpc/RpcInvocation.java   | 73 +++++++++++++++++-----
 .../org/apache/dubbo/rpc/filter/GenericFilter.java |  2 +-
 .../dubbo/rpc/proxy/InvokerInvocationHandler.java  |  2 +-
 .../apache/dubbo/rpc/support/MockInvocation.java   |  6 ++
 .../dubbo/rpc/protocol/dubbo/DubboProtocol.java    |  2 +-
 .../rpc/protocol/tri/AbstractServerStream.java     |  7 +--
 12 files changed, 109 insertions(+), 26 deletions(-)

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 3923937..9a0d7c1 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
@@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.cluster.directory;
 import org.apache.dubbo.rpc.AttachmentsAdapter;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ServiceModel;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -130,6 +131,11 @@ public class MockDirInvocation implements Invocation {
     }
 
     @Override
+    public ServiceModel getServiceModel() {
+        return null;
+    }
+
+    @Override
     public Map<Object, Object> getAttributes() {
         return null;
     }
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 1c4867f..654ecab 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -31,6 +31,7 @@ import org.apache.dubbo.common.utils.LRUCache;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.rpc.model.ScopeModel;
+import org.apache.dubbo.rpc.model.ServiceModel;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
@@ -548,12 +549,21 @@ class URL implements Serializable {
     }
 
     public URL setScopeModel(ScopeModel scopeModel) {
-        this.attributes.put(CommonConstants.SCOPE_MODEL, scopeModel);
+        putAttribute(CommonConstants.SCOPE_MODEL, scopeModel);
         return this;
     }
 
     public ScopeModel getScopeModel() {
-        return (ScopeModel) this.attributes.get(CommonConstants.SCOPE_MODEL);
+        return (ScopeModel) getAttribute(CommonConstants.SCOPE_MODEL);
+    }
+
+    public URL setServiceModel(ServiceModel serviceModel) {
+        putAttribute(CommonConstants.SERVICE_MODEL, serviceModel);
+        return this;
+    }
+
+    public ServiceModel getServiceModel() {
+        return (ServiceModel) getAttribute(CommonConstants.SERVICE_MODEL);
     }
 
     protected Map<String, Number> getNumbers() {
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index e40550c..67de259 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -449,4 +449,6 @@ public interface CommonConstants {
     String SERVICE_NAME_MAPPING_KEY = "service-name-mapping";
 
     String SCOPE_MODEL = "scopeModel";
+
+    String SERVICE_MODEL = "serviceModel";
 }
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 f53e159..1c10ee4 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
@@ -17,6 +17,8 @@
 
 package com.alibaba.dubbo.rpc;
 
+import org.apache.dubbo.rpc.model.ServiceModel;
+
 import java.util.Collections;
 import java.util.Map;
 
@@ -75,6 +77,11 @@ public interface Invocation extends 
org.apache.dubbo.rpc.Invocation {
     }
 
     @Override
+    default ServiceModel getServiceModel() {
+        return null;
+    }
+
+    @Override
     default Object put(Object key, Object value) {
         return null;
     }
@@ -158,6 +165,11 @@ public interface Invocation extends 
org.apache.dubbo.rpc.Invocation {
         }
 
         @Override
+        public ServiceModel getServiceModel() {
+            return delegate.getServiceModel();
+        }
+
+        @Override
         public Object put(Object key, Object value) {
             return delegate.put(key, value);
         }
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 a2cb52e..299dbce 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
@@ -19,6 +19,7 @@ package org.apache.dubbo.service;
 import org.apache.dubbo.rpc.AttachmentsAdapter;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ServiceModel;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -132,6 +133,11 @@ public class MockInvocation implements Invocation {
     }
 
     @Override
+    public ServiceModel getServiceModel() {
+        return null;
+    }
+
+    @Override
     public Map<Object, Object> getAttributes() {
         return null;
     }
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 bedd350..04bbdc8 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
@@ -17,6 +17,7 @@
 package org.apache.dubbo.rpc;
 
 import org.apache.dubbo.common.Experimental;
+import org.apache.dubbo.rpc.model.ServiceModel;
 
 import java.util.Map;
 import java.util.stream.Stream;
@@ -138,6 +139,8 @@ public interface Invocation {
      */
     Invoker<?> getInvoker();
 
+    ServiceModel getServiceModel();
+
     Object put(Object key, Object value);
 
     Object get(Object key);
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 5905549..c7e7187 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
@@ -22,6 +22,7 @@ import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 import org.apache.dubbo.rpc.model.MethodDescriptor;
 import org.apache.dubbo.rpc.model.ServiceDescriptor;
+import org.apache.dubbo.rpc.model.ServiceModel;
 import org.apache.dubbo.rpc.model.ServiceRepository;
 import org.apache.dubbo.rpc.support.RpcUtils;
 
@@ -54,6 +55,7 @@ public class RpcInvocation implements Invocation, 
Serializable {
     private String targetServiceUniqueName;
     private String protocolServiceKey;
 
+    private ServiceModel serviceModel;
     private String methodName;
     private String serviceName;
 
@@ -85,7 +87,7 @@ public class RpcInvocation implements Invocation, 
Serializable {
     }
 
     public RpcInvocation(Invocation invocation, Invoker<?> invoker) {
-        this(invocation.getMethodName(), invocation.getServiceName(), 
invocation.getProtocolServiceKey(),
+        this(invocation.getServiceModel(), invocation.getMethodName(), 
invocation.getServiceName(), invocation.getProtocolServiceKey(),
                 invocation.getParameterTypes(), invocation.getArguments(), new 
LinkedHashMap<>(invocation.getObjectAttachments()),
                 invocation.getInvoker(), invocation.getAttributes());
         if (invoker != null) {
@@ -115,29 +117,56 @@ public class RpcInvocation implements Invocation, 
Serializable {
     }
 
     public RpcInvocation(Invocation invocation) {
-        this(invocation.getMethodName(), invocation.getServiceName(), 
invocation.getProtocolServiceKey(), invocation.getParameterTypes(),
+        this(invocation.getServiceModel(), invocation.getMethodName(), 
invocation.getServiceName(), invocation.getProtocolServiceKey(), 
invocation.getParameterTypes(),
                 invocation.getArguments(), invocation.getObjectAttachments(), 
invocation.getInvoker(), invocation.getAttributes());
         this.targetServiceUniqueName = invocation.getTargetServiceUniqueName();
     }
 
+    public RpcInvocation(ServiceModel serviceModel, Method method, String 
serviceName, String protocolServiceKey, Object[] arguments) {
+        this(serviceModel, method, serviceName, protocolServiceKey, arguments, 
null, null);
+    }
+
+    @Deprecated
     public RpcInvocation(Method method, String serviceName, String 
protocolServiceKey, Object[] arguments) {
-        this(method, serviceName, protocolServiceKey, arguments, null, null);
+        this(null, method, serviceName, protocolServiceKey, arguments, null, 
null);
     }
 
+    public RpcInvocation(ServiceModel serviceModel, Method method, String 
serviceName, String protocolServiceKey, Object[] arguments, Map<String, Object> 
attachment, Map<Object, Object> attributes) {
+        this(serviceModel, method.getName(), serviceName, protocolServiceKey, 
method.getParameterTypes(), arguments, attachment, null, attributes);
+    }
+
+    @Deprecated
     public RpcInvocation(Method method, String serviceName, String 
protocolServiceKey, Object[] arguments, Map<String, Object> attachment, 
Map<Object, Object> attributes) {
-        this(method.getName(), serviceName, protocolServiceKey, 
method.getParameterTypes(), arguments, attachment, null, attributes);
+        this(null, method.getName(), serviceName, protocolServiceKey, 
method.getParameterTypes(), arguments, attachment, null, attributes);
     }
 
+    public RpcInvocation(ServiceModel serviceModel, String methodName, String 
serviceName, String protocolServiceKey, Class<?>[] parameterTypes, Object[] 
arguments) {
+        this(serviceModel, methodName, serviceName, protocolServiceKey, 
parameterTypes, arguments, null, null, null);
+    }
+
+    @Deprecated
     public RpcInvocation(String methodName, String serviceName, String 
protocolServiceKey, Class<?>[] parameterTypes, Object[] arguments) {
-        this(methodName, serviceName, protocolServiceKey, parameterTypes, 
arguments, null, null, null);
+        this(null, methodName, serviceName, protocolServiceKey, 
parameterTypes, arguments, null, null, null);
+    }
+
+    public RpcInvocation(ServiceModel serviceModel, String methodName, String 
serviceName, String protocolServiceKey, Class<?>[] parameterTypes, Object[] 
arguments, Map<String, Object> attachments) {
+        this(serviceModel, methodName, serviceName, protocolServiceKey, 
parameterTypes, arguments, attachments, null, null);
     }
 
+    @Deprecated
     public RpcInvocation(String methodName, String serviceName, String 
protocolServiceKey, Class<?>[] parameterTypes, Object[] arguments, Map<String, 
Object> attachments) {
-        this(methodName, serviceName, protocolServiceKey, parameterTypes, 
arguments, attachments, null, null);
+        this(null, methodName, serviceName, protocolServiceKey, 
parameterTypes, arguments, attachments, null, null);
     }
 
+    @Deprecated
     public RpcInvocation(String methodName, String serviceName, String 
protocolServiceKey, Class<?>[] parameterTypes, Object[] arguments,
                          Map<String, Object> attachments, Invoker<?> invoker, 
Map<Object, Object> attributes) {
+        this(null, methodName, serviceName, protocolServiceKey, 
parameterTypes, arguments, attachments, invoker, attributes);
+    }
+
+    public RpcInvocation(ServiceModel serviceModel, String methodName, String 
serviceName, String protocolServiceKey, Class<?>[] parameterTypes, Object[] 
arguments,
+                         Map<String, Object> attachments, Invoker<?> invoker, 
Map<Object, Object> attributes) {
+        this.serviceModel = serviceModel;
         this.methodName = methodName;
         this.serviceName = serviceName;
         this.protocolServiceKey = protocolServiceKey;
@@ -150,20 +179,25 @@ public class RpcInvocation implements Invocation, 
Serializable {
     }
 
     private void initParameterDesc() {
-        ServiceRepository repository = 
ApplicationModel.defaultModel().getApplicationServiceRepository();
-        if (StringUtils.isNotEmpty(serviceName)) {
-            ServiceDescriptor serviceDescriptor = 
repository.lookupService(serviceName);
-            if (serviceDescriptor != null) {
-                MethodDescriptor methodDescriptor = 
serviceDescriptor.getMethod(methodName, parameterTypes);
-                if (methodDescriptor != null) {
-                    this.parameterTypesDesc = methodDescriptor.getParamDesc();
-                    this.compatibleParamSignatures = 
methodDescriptor.getCompatibleParamSignatures();
-                    this.returnTypes = methodDescriptor.getReturnTypes();
-                    this.returnType = methodDescriptor.getReturnClass();
-                }
+        ServiceDescriptor serviceDescriptor;
+        if (serviceModel != null) {
+            serviceDescriptor = serviceModel.getServiceModel();
+        } else {
+            ServiceRepository repository = 
ApplicationModel.defaultModel().getApplicationServiceRepository();
+            serviceDescriptor = repository.lookupService(serviceName);
+        }
+
+        if (serviceDescriptor != null) {
+            MethodDescriptor methodDescriptor = 
serviceDescriptor.getMethod(methodName, parameterTypes);
+            if (methodDescriptor != null) {
+                this.parameterTypesDesc = methodDescriptor.getParamDesc();
+                this.compatibleParamSignatures = 
methodDescriptor.getCompatibleParamSignatures();
+                this.returnTypes = methodDescriptor.getReturnTypes();
+                this.returnType = methodDescriptor.getReturnClass();
             }
         }
 
+
         if (parameterTypesDesc == null) {
             this.parameterTypesDesc = 
ReflectUtils.getDesc(this.getParameterTypes());
             this.compatibleParamSignatures = 
Stream.of(this.parameterTypes).map(Class::getName).toArray(String[]::new);
@@ -452,6 +486,11 @@ public class RpcInvocation implements Invocation, 
Serializable {
     }
 
     @Override
+    public ServiceModel getServiceModel() {
+        return serviceModel;
+    }
+
+    @Override
     public String toString() {
         return "RpcInvocation [methodName=" + methodName + ", parameterTypes="
                 + Arrays.toString(parameterTypes) + ", arguments=" + 
Arrays.toString(arguments)
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 8b7010a..d00da0f 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
@@ -176,7 +176,7 @@ public class GenericFilter implements Filter, 
Filter.Listener {
                 }
 
                 RpcInvocation rpcInvocation =
-                        new RpcInvocation(method, 
invoker.getInterface().getName(), invoker.getUrl().getProtocolServiceKey(), 
args,
+                        new RpcInvocation(invoker.getUrl().getServiceModel(), 
method, invoker.getInterface().getName(), 
invoker.getUrl().getProtocolServiceKey(), args,
                                 inv.getObjectAttachments(), 
inv.getAttributes());
                 rpcInvocation.setInvoker(inv.getInvoker());
                 
rpcInvocation.setTargetServiceUniqueName(inv.getTargetServiceUniqueName());
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 8c5738d..712bbe6 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
@@ -80,7 +80,7 @@ public class InvokerInvocationHandler implements 
InvocationHandler {
         } else if (parameterTypes.length == 1 && "equals".equals(methodName)) {
             return invoker.equals(args[0]);
         }
-        RpcInvocation rpcInvocation = new RpcInvocation(method, 
invoker.getInterface().getName(), protocolServiceKey, args);
+        RpcInvocation rpcInvocation = new RpcInvocation(consumerModel, method, 
invoker.getInterface().getName(), protocolServiceKey, args);
         String serviceKey = url.getServiceKey();
         rpcInvocation.setTargetServiceUniqueName(serviceKey);
 
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 8ebe8ac..be78c14 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
@@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.support;
 import org.apache.dubbo.rpc.AttachmentsAdapter;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ServiceModel;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -118,6 +119,11 @@ public class MockInvocation implements Invocation {
     }
 
     @Override
+    public ServiceModel getServiceModel() {
+        return null;
+    }
+
+    @Override
     public Object put(Object key, Object value) {
         return null;
     }
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 4319bd2..8452d08 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
@@ -195,7 +195,7 @@ public class DubboProtocol extends AbstractProtocol {
                 return null;
             }
 
-            RpcInvocation invocation = new RpcInvocation(method, 
url.getParameter(INTERFACE_KEY), "", new Class<?>[0], new Object[0]);
+            RpcInvocation invocation = new 
RpcInvocation(url.getServiceModel(), method, url.getParameter(INTERFACE_KEY), 
"", new Class<?>[0], new Object[0]);
             invocation.setAttachment(PATH_KEY, url.getPath());
             invocation.setAttachment(GROUP_KEY, url.getGroup());
             invocation.setAttachment(INTERFACE_KEY, 
url.getParameter(INTERFACE_KEY));
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractServerStream.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractServerStream.java
index 1b990a7..b742248 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractServerStream.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractServerStream.java
@@ -112,11 +112,10 @@ public abstract class AbstractServerStream extends 
AbstractStream implements Str
     }
 
     protected RpcInvocation buildInvocation(Metadata metadata) {
-        RpcInvocation inv = new RpcInvocation();
-        inv.setServiceName(getServiceDescriptor().getServiceName());
+        RpcInvocation inv = new RpcInvocation(getUrl().getServiceModel(),
+            getMethodName(), getServiceDescriptor().getServiceName(),
+            getUrl().getProtocolServiceKey(), 
getMethodDescriptor().getParameterClasses(), new Object[0]);
         inv.setTargetServiceUniqueName(getUrl().getServiceKey());
-        inv.setMethodName(getMethodDescriptor().getMethodName());
-        inv.setParameterTypes(getMethodDescriptor().getParameterClasses());
         inv.setReturnTypes(getMethodDescriptor().getReturnTypes());
 
         final Map<String, Object> attachments = 
parseMetadataToAttachmentMap(metadata);

Reply via email to