You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/13 07:24:42 UTC
[dubbo] 01/14: can fetch classloader from ConsumerModel,
also support group in ConfigChangeEvent
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master-hsf
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 6261f36a96e3e0f1a3a260f861f3817ef5e76969
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Fri Nov 1 11:00:04 2019 +0800
can fetch classloader from ConsumerModel, also support group in ConfigChangeEvent
---
.../org/apache/dubbo/config/ReferenceConfig.java | 50 ++++++++--------------
.../dubbo/configcenter/ConfigChangeEvent.java | 16 ++++++-
.../org/apache/dubbo/rpc/model/ConsumerModel.java | 20 ++++++---
3 files changed, 47 insertions(+), 39 deletions(-)
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 0b26e11..d082bbe 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
@@ -48,7 +48,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;
@@ -244,6 +243,17 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
}
checkInterfaceAndMethods(interfaceClass, methods);
}
+
+ //init serivceMetadata
+ serviceMetadata.setVersion(version);
+ serviceMetadata.setGroup(group);
+ serviceMetadata.setDefaultGroup(group);
+ serviceMetadata.setServiceKey(URL.buildKey(interfaceName, group, version));
+ serviceMetadata.setServiceType(getActualInterface());
+ serviceMetadata.setServiceInterfaceName(interfaceName);
+ ConsumerModel consumerModel = new ConsumerModel(serviceMetadata);
+ ApplicationModel.initConsumerModel(URL.buildKey(interfaceName, group, version), consumerModel);
+
resolveFile();
checkApplication();
checkMetadataReport();
@@ -257,8 +267,6 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
}
public synchronized T get() {
- checkAndUpdateSubConfigs();
-
if (destroyed) {
throw new IllegalStateException("The invoker of ReferenceConfig(" + url + ") has already destroyed!");
}
@@ -289,17 +297,11 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
if (initialized) {
return;
}
+
+ checkAndUpdateSubConfigs();
checkStubAndLocal(interfaceClass);
checkMock(interfaceClass);
- //init serivceMetadata
- serviceMetadata.setVersion(version);
- serviceMetadata.setGroup(group);
- serviceMetadata.setDefaultGroup(group);
- serviceMetadata.setServiceType(getActualInterface());
- serviceMetadata.setServiceInterfaceName(interfaceName);
- serviceMetadata.setServiceKey(URL.buildKey(interfaceName, group, version));
-
Map<String, String> map = new HashMap<String, String>();
map.put(SIDE_KEY, CONSUMER_SIDE);
appendRuntimeParameters(map);
@@ -344,25 +346,25 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
attributes.put(methodConfig.getName(), asyncMethodInfo);
}
}
+
+ ApplicationModel.getConsumerModel(URL.buildKey(interfaceName, group, version)).init(attributes);
}
+
String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
} else if (isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
}
- map.put(REGISTER_IP_KEY, hostToRegistry);
- serviceMetadata.getAttachments().putAll(map);
-
- ApplicationModel.initConsumerModel(URL.buildKey(interfaceName, group, version), buildConsumerModel(attributes, serviceMetadata));
+ map.put(REGISTER_IP_KEY, hostToRegistry);
ref = createProxy(map);
-
-
serviceMetadata.setTarget(ref);
serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);
+ serviceMetadata.getAttachments().putAll(map);
+
initialized = true;
}
@@ -378,20 +380,6 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
return actualInterface;
}
- private ConsumerModel buildConsumerModel(Map<String, Object> attributes, ServiceMetadata metadata) {
- 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(attributes, metadata);
- }
-
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
private T createProxy(Map<String, String> map) {
if (shouldJvmRefer(map)) {
diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java b/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java
index cdedd15..bfd99c4 100644
--- a/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java
+++ b/dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/ConfigChangeEvent.java
@@ -23,7 +23,7 @@ package org.apache.dubbo.configcenter;
*/
public class ConfigChangeEvent {
private final String key;
-
+ private final String group;
private final String value;
private final ConfigChangeType changeType;
@@ -31,8 +31,17 @@ public class ConfigChangeEvent {
this(key, value, ConfigChangeType.MODIFIED);
}
+ public ConfigChangeEvent(String key, String group, String value) {
+ this(key, group, value, ConfigChangeType.MODIFIED);
+ }
+
public ConfigChangeEvent(String key, String value, ConfigChangeType changeType) {
+ this(key, null, value, changeType);
+ }
+
+ public ConfigChangeEvent(String key, String group, String value, ConfigChangeType changeType) {
this.key = key;
+ this.group = group;
this.value = value;
this.changeType = changeType;
}
@@ -41,6 +50,10 @@ public class ConfigChangeEvent {
return key;
}
+ public String getGroup() {
+ return group;
+ }
+
public String getValue() {
return value;
}
@@ -53,6 +66,7 @@ public class ConfigChangeEvent {
public String toString() {
return "ConfigChangeEvent{" +
"key='" + key + '\'' +
+ ", group='" + group + '\'' +
", value='" + value + '\'' +
", changeType=" + changeType +
'}';
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 0e4d4c2..c778ca8 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
@@ -28,24 +28,30 @@ import java.util.Optional;
* Consumer Model which is about subscribed services.
*/
public class ConsumerModel {
- private final ServiceMetadata serviceMetadata;
- private final Map<Method, ConsumerMethodModel> methodModels = new IdentityHashMap<Method, ConsumerMethodModel>();
+ private ServiceMetadata serviceMetadata;
+ private Map<Method, ConsumerMethodModel> methodModels = new IdentityHashMap<Method, ConsumerMethodModel>();
/**
* 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 attributes Attributes of methods.
- * @param metadata
+ * @param serviceMetadata
*/
- public ConsumerModel(Map<String, Object> attributes, ServiceMetadata metadata) {
- this.serviceMetadata = metadata;
- for (Method method : metadata.getServiceType().getMethods()) {
+ public ConsumerModel(ServiceMetadata serviceMetadata) {
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ public void init(Map<String, Object> attributes) {
+ for (Method method : serviceMetadata.getServiceType().getMethods()) {
methodModels.put(method, new ConsumerMethodModel(method, attributes));
}
}
+ public ClassLoader getClassLoader() {
+ return serviceMetadata.getServiceType().getClassLoader();
+ }
+
/**
* @return serviceMetadata
*/