You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/08/28 15:00:27 UTC

[dubbo] branch 3.0-multi-instances updated (bba7e0f -> 7d8e09a)

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

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


    from bba7e0f  Fix scope model of registry, metadata, cluster and so on
     new 221b7a4  exact ServiceModel from ProviderModel and ConsumerModel
     new 7d8e09a  Add ASF license header for ScopeBeanFactoryInitializer

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../beans/factory/ScopeBeanFactoryInitializer.java |  16 +++
 .../org/apache/dubbo/rpc/model/ConsumerModel.java  | 106 +++---------------
 .../org/apache/dubbo/rpc/model/ProviderModel.java  |  80 +++-----------
 .../org/apache/dubbo/rpc/model/ServiceModel.java   | 122 +++++++++++++++++++++
 4 files changed, 168 insertions(+), 156 deletions(-)
 create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java

[dubbo] 01/02: exact ServiceModel from ProviderModel and ConsumerModel

Posted by al...@apache.org.
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 221b7a4150bcaf292b683e9177aed275c93c3c9c
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Sat Aug 28 22:58:34 2021 +0800

    exact ServiceModel from ProviderModel and ConsumerModel
---
 .../org/apache/dubbo/rpc/model/ConsumerModel.java  | 106 +++---------------
 .../org/apache/dubbo/rpc/model/ProviderModel.java  |  80 +++-----------
 .../org/apache/dubbo/rpc/model/ServiceModel.java   | 122 +++++++++++++++++++++
 3 files changed, 152 insertions(+), 156 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
index 81b1a88..f6df44d 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ConsumerModel.java
@@ -16,9 +16,7 @@
  */
 package org.apache.dubbo.rpc.model;
 
-import org.apache.dubbo.common.BaseServiceMetadata;
 import org.apache.dubbo.common.utils.Assert;
-import org.apache.dubbo.common.utils.ClassUtils;
 import org.apache.dubbo.config.ReferenceConfigBase;
 
 import java.lang.reflect.Method;
@@ -34,15 +32,11 @@ import java.util.TreeSet;
 /**
  * This model is bound to your reference's configuration, for example, group, version or method level configuration.
  */
-public class ConsumerModel {
-    private String serviceKey;
-    private final ServiceDescriptor serviceModel;
-    private final ReferenceConfigBase<?> referenceConfig;
+public class ConsumerModel extends ServiceModel {
     private final Set<String> apps = new TreeSet<>();
 
-    private Object proxyObject;
-
     private final Map<String, AsyncMethodInfo> methodConfigs;
+    private Map<Method, ConsumerMethodModel> methodModels = new HashMap<>();
 
     /**
      * This constructor create an instance of ConsumerModel and passed objects should not be null.
@@ -58,57 +52,29 @@ public class ConsumerModel {
                          ReferenceConfigBase<?> referenceConfig,
                          Map<String, AsyncMethodInfo> methodConfigs) {
 
+        super(proxyObject, serviceKey, serviceModel, referenceConfig);
         Assert.notEmptyString(serviceKey, "Service name can't be null or blank");
 
-        this.serviceKey = serviceKey;
-        this.proxyObject = proxyObject;
-        this.serviceModel = serviceModel;
-        this.referenceConfig = referenceConfig;
         this.methodConfigs = methodConfigs == null ? new HashMap<>() : methodConfigs;
     }
 
-    /**
-     * Return the proxy object used by called while creating instance of ConsumerModel
-     *
-     * @return
-     */
-    public Object getProxyObject() {
-        return proxyObject;
-    }
-
-    public void setProxyObject(Object proxyObject) {
-        this.proxyObject = proxyObject;
-    }
-
-    /**
-     * Return all method models for the current service
-     *
-     * @return method model list
-     */
-    public Set<MethodDescriptor> getAllMethods() {
-        return serviceModel.getAllMethods();
-    }
+    public ConsumerModel(String serviceKey,
+                         Object proxyObject,
+                         ServiceDescriptor serviceModel,
+                         ReferenceConfigBase<?> referenceConfig,
+                         ServiceMetadata metadata,
+                         Map<String, AsyncMethodInfo> methodConfigs) {
 
-    public Class<?> getServiceInterfaceClass() {
-        return serviceModel.getServiceInterfaceClass();
-    }
+        super(proxyObject, serviceKey, serviceModel, referenceConfig, metadata);
+        Assert.notEmptyString(serviceKey, "Service name can't be null or blank");
 
-    public String getServiceKey() {
-        return serviceKey;
+        this.methodConfigs = methodConfigs == null ? new HashMap<>() : methodConfigs;
     }
 
     public AsyncMethodInfo getMethodConfig(String methodName) {
         return methodConfigs.get(methodName);
     }
 
-    public ServiceDescriptor getServiceModel() {
-        return serviceModel;
-    }
-
-    public ReferenceConfigBase getReferenceConfig() {
-        return referenceConfig;
-    }
-
     public Set<String> getApps() {
         return apps;
     }
@@ -117,41 +83,17 @@ public class ConsumerModel {
         return methodConfigs.get(methodName);
     }
 
-    /* *************** Start, metadata compatible **************** */
-
-    private ServiceMetadata serviceMetadata;
-    private Map<Method, ConsumerMethodModel> methodModels = new HashMap<>();
-
-    public ConsumerModel(String serviceKey,
-                         Object proxyObject,
-                         ServiceDescriptor serviceModel,
-                         ReferenceConfigBase<?> referenceConfig,
-                         ServiceMetadata metadata,
-                         Map<String, AsyncMethodInfo> methodConfigs) {
-
-        this(serviceKey, proxyObject, serviceModel, referenceConfig, methodConfigs);
-        this.serviceMetadata = metadata;
-    }
-
-    public void setServiceKey(String serviceKey) {
-        this.serviceKey = serviceKey;
-        if (serviceMetadata != null) {
-            serviceMetadata.setServiceKey(serviceKey);
-            serviceMetadata.setGroup(BaseServiceMetadata.groupFromServiceKey(serviceKey));
-        }
-    }
-
     public void initMethodModels() {
         Class<?>[] interfaceList;
-        if (proxyObject == null) {
-            Class<?> serviceInterfaceClass = referenceConfig.getServiceInterfaceClass();
+        if (getProxyObject() == null) {
+            Class<?> serviceInterfaceClass = getReferenceConfig().getServiceInterfaceClass();
             if (serviceInterfaceClass != null) {
                 interfaceList = new Class[]{serviceInterfaceClass};
             } else {
                 interfaceList = new Class[0];
             }
         } else {
-            interfaceList = proxyObject.getClass().getInterfaces();
+            interfaceList = getProxyObject().getClass().getInterfaces();
         }
         for (Class<?> interfaceClass : interfaceList) {
             for (Method method : interfaceClass.getMethods()) {
@@ -160,18 +102,6 @@ public class ConsumerModel {
         }
     }
 
-    public ClassLoader getClassLoader() {
-        Class<?> serviceType = serviceMetadata.getServiceType();
-        return serviceType != null ? serviceType.getClassLoader() : ClassUtils.getClassLoader();
-    }
-
-    /**
-     * @return serviceMetadata
-     */
-    public ServiceMetadata getServiceMetadata() {
-        return serviceMetadata;
-    }
-
     /**
      * Return method model for the given method on consumer side
      *
@@ -214,10 +144,4 @@ public class ConsumerModel {
     public List<ConsumerMethodModel> getAllMethodModels() {
         return new ArrayList<>(methodModels.values());
     }
-
-    public String getServiceName() {
-        return this.serviceMetadata.getServiceKey();
-    }
-
-
 }
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
index a640204..2aab894 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java
@@ -16,7 +16,6 @@
  */
 package org.apache.dubbo.rpc.model;
 
-import org.apache.dubbo.common.BaseServiceMetadata;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.config.ServiceConfigBase;
 
@@ -27,56 +26,42 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * ProviderModel is about published services
  */
-public class ProviderModel {
-    private String serviceKey;
-    private final Object serviceInstance;
-    private final ServiceDescriptor serviceModel;
-    private final ServiceConfigBase<?> serviceConfig;
+public class ProviderModel extends ServiceModel {
     private final List<RegisterStatedURL> urls;
+    private final Map<String, List<ProviderMethodModel>> methods = new HashMap<String, List<ProviderMethodModel>>();
 
     public ProviderModel(String serviceKey,
                          Object serviceInstance,
                          ServiceDescriptor serviceModel,
                          ServiceConfigBase<?> serviceConfig) {
+        super(serviceInstance, serviceKey, serviceModel, serviceConfig);
         if (null == serviceInstance) {
             throw new IllegalArgumentException("Service[" + serviceKey + "]Target is NULL.");
         }
 
-        this.serviceKey = serviceKey;
-        this.serviceInstance = serviceInstance;
-        this.serviceModel = serviceModel;
-        this.serviceConfig = serviceConfig;
         this.urls = new ArrayList<>(1);
     }
 
-    public String getServiceKey() {
-        return serviceKey;
-    }
-
+    public ProviderModel(String serviceKey,
+                         Object serviceInstance,
+                         ServiceDescriptor serviceModel,
+                         ServiceConfigBase<?> serviceConfig,
+                         ServiceMetadata serviceMetadata) {
+        super(serviceInstance, serviceKey, serviceModel, serviceConfig, serviceMetadata);
+        if (null == serviceInstance) {
+            throw new IllegalArgumentException("Service[" + serviceKey + "]Target is NULL.");
+        }
 
-    public Class<?> getServiceInterfaceClass() {
-        return serviceModel.getServiceInterfaceClass();
+        initMethod(serviceModel.getServiceInterfaceClass());
+        this.urls = new ArrayList<>(1);
     }
 
     public Object getServiceInstance() {
-        return serviceInstance;
-    }
-
-    public Set<MethodDescriptor> getAllMethods() {
-        return serviceModel.getAllMethods();
-    }
-
-    public ServiceDescriptor getServiceModel() {
-        return serviceModel;
-    }
-
-    public ServiceConfigBase getServiceConfig() {
-        return serviceConfig;
+        return getProxyObject();
     }
 
     public List<RegisterStatedURL> getStatedUrl() {
@@ -125,35 +110,6 @@ public class ProviderModel {
         }
     }
 
-    /* *************** Start, metadata compatible **************** */
-
-    private ServiceMetadata serviceMetadata;
-    private final Map<String, List<ProviderMethodModel>> methods = new HashMap<String, List<ProviderMethodModel>>();
-
-    public ProviderModel(String serviceKey,
-                         Object serviceInstance,
-                         ServiceDescriptor serviceModel,
-                         ServiceConfigBase<?> serviceConfig,
-                         ServiceMetadata serviceMetadata) {
-        this(serviceKey, serviceInstance, serviceModel, serviceConfig);
-
-        this.serviceMetadata = serviceMetadata;
-        initMethod(serviceModel.getServiceInterfaceClass());
-    }
-
-
-    public void setServiceKey(String serviceKey) {
-        this.serviceKey = serviceKey;
-        if (serviceMetadata != null) {
-            serviceMetadata.setServiceKey(serviceKey);
-            serviceMetadata.setGroup(BaseServiceMetadata.groupFromServiceKey(serviceKey));
-        }
-    }
-
-    public String getServiceName() {
-        return this.serviceMetadata.getServiceKey();
-    }
-
     public List<ProviderMethodModel> getAllMethodModels() {
         List<ProviderMethodModel> result = new ArrayList<ProviderMethodModel>();
         for (List<ProviderMethodModel> models : methods.values()) {
@@ -195,10 +151,4 @@ public class ProviderModel {
         }
     }
 
-    /**
-     * @return serviceMetadata
-     */
-    public ServiceMetadata getServiceMetadata() {
-        return serviceMetadata;
-    }
 }
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java
new file mode 100644
index 0000000..3bba258
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceModel.java
@@ -0,0 +1,122 @@
+/*
+ * 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.BaseServiceMetadata;
+import org.apache.dubbo.common.utils.ClassUtils;
+import org.apache.dubbo.config.AbstractInterfaceConfig;
+import org.apache.dubbo.config.ReferenceConfigBase;
+import org.apache.dubbo.config.ServiceConfigBase;
+
+import java.util.Set;
+
+public class ServiceModel {
+    private String serviceKey;
+    private Object proxyObject;
+    private final ServiceDescriptor serviceModel;
+    private final AbstractInterfaceConfig config;
+
+    private ServiceMetadata serviceMetadata;
+
+    public ServiceModel(Object proxyObject, String serviceKey, ServiceDescriptor serviceModel, AbstractInterfaceConfig config) {
+        this.proxyObject = proxyObject;
+        this.serviceKey = serviceKey;
+        this.serviceModel = serviceModel;
+        this.config = config;
+    }
+
+    public ServiceModel(Object proxyObject, String serviceKey, ServiceDescriptor serviceModel, AbstractInterfaceConfig config, ServiceMetadata serviceMetadata) {
+        this.proxyObject = proxyObject;
+        this.serviceKey = serviceKey;
+        this.serviceModel = serviceModel;
+        this.config = config;
+        this.serviceMetadata = serviceMetadata;
+    }
+
+    public String getServiceKey() {
+        return serviceKey;
+    }
+
+    public void setProxyObject(Object proxyObject) {
+        this.proxyObject = proxyObject;
+    }
+
+    public Object getProxyObject() {
+        return proxyObject;
+    }
+
+    public ServiceDescriptor getServiceModel() {
+        return serviceModel;
+    }
+
+    public ClassLoader getClassLoader() {
+        Class<?> serviceType = serviceMetadata.getServiceType();
+        return serviceType != null ? serviceType.getClassLoader() : ClassUtils.getClassLoader();
+    }
+
+    /**
+     * Return all method models for the current service
+     *
+     * @return method model list
+     */
+    public Set<MethodDescriptor> getAllMethods() {
+        return serviceModel.getAllMethods();
+    }
+
+    public Class<?> getServiceInterfaceClass() {
+        return serviceModel.getServiceInterfaceClass();
+    }
+
+    public AbstractInterfaceConfig getConfig() {
+        return config;
+    }
+
+    public ReferenceConfigBase<?> getReferenceConfig() {
+        if(config instanceof ReferenceConfigBase) {
+            return (ReferenceConfigBase<?>) config;
+        } else {
+            throw new IllegalArgumentException("Current ServiceModel is not a ConsumerModel");
+        }
+    }
+
+    public ServiceConfigBase<?> getServiceConfig() {
+        if(config instanceof ServiceConfigBase) {
+            return (ServiceConfigBase<?>) config;
+        } else {
+            throw new IllegalArgumentException("Current ServiceModel is not a ProviderModel");
+        }
+    }
+
+    public void setServiceKey(String serviceKey) {
+        this.serviceKey = serviceKey;
+        if (serviceMetadata != null) {
+            serviceMetadata.setServiceKey(serviceKey);
+            serviceMetadata.setGroup(BaseServiceMetadata.groupFromServiceKey(serviceKey));
+        }
+    }
+
+    public String getServiceName() {
+        return this.serviceMetadata.getServiceKey();
+    }
+
+    /**
+     * @return serviceMetadata
+     */
+    public ServiceMetadata getServiceMetadata() {
+        return serviceMetadata;
+    }
+}

[dubbo] 02/02: Add ASF license header for ScopeBeanFactoryInitializer

Posted by al...@apache.org.
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 7d8e09a4cc8df61ecb5c2c69439ba88635423ec1
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Sat Aug 28 22:59:38 2021 +0800

    Add ASF license header for ScopeBeanFactoryInitializer
---
 .../beans/factory/ScopeBeanFactoryInitializer.java       | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/beans/factory/ScopeBeanFactoryInitializer.java b/dubbo-common/src/main/java/org/apache/dubbo/common/beans/factory/ScopeBeanFactoryInitializer.java
index 33c9136..07ced8d 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/beans/factory/ScopeBeanFactoryInitializer.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/beans/factory/ScopeBeanFactoryInitializer.java
@@ -1,3 +1,19 @@
+/*
+ * 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.common.beans.factory;
 
 import org.apache.dubbo.rpc.model.ApplicationModel;