Skip to content

Commit

Permalink
Merge branch '3.3' into feat/remove_monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHZM authored Dec 14, 2023
2 parents c90cb4b + ad803e1 commit 00e4d60
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
Expand Down Expand Up @@ -758,6 +759,20 @@ public void setMethods(List<? extends MethodConfig> methods) {
this.methods = (methods != null) ? new ArrayList<>(methods) : null;
}

/**
* It is only used in native scenarios to get methodConfigs.
* @param methodsJson
*/
public void setMethodsJson(List<String> methodsJson) {
if (methodsJson != null) {
this.methods = new ArrayList<>();
methodsJson.forEach(
(methodConfigJson) -> methods.add(JsonUtils.toJavaObject(methodConfigJson, MethodConfig.class)));
} else {
this.methods = null;
}
}

public void addMethod(MethodConfig methodConfig) {
if (this.methods == null) {
this.methods = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ public List<String> getPrefixes() {
List<String> prefixes = new ArrayList<>();
prefixes.add(parentPrefix + "." + this.getName());
return prefixes;
} else {
throw new IllegalStateException("The parent prefix of MethodConfig is null");
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
Expand Down Expand Up @@ -468,4 +469,15 @@ public void setInterfaceClass(Class<?> interfaceClass) {
public void setInterfaceName(String interfaceName) {
this.interfaceName = interfaceName;
}

/**
* It is only used in native scenarios to get referenceProps
* because attribute is not passed by BeanDefinition by default.
* @param referencePropsJson
*/
public void setReferencePropsJson(String referencePropsJson) {
if (StringUtils.isNotEmpty(referencePropsJson)) {
this.referenceProps = JsonUtils.toJavaObject(referencePropsJson, Map.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class AotWithSpringDetector {
*/
public static final String AOT_ENABLED = "spring.aot.enabled";

private static final String AOT_PROCESSING = "spring.aot.processing";

/**
* Determine whether AOT optimizations must be considered at runtime. This
* is mandatory in a native image but can be triggered on the JVM using
Expand All @@ -40,4 +42,8 @@ public abstract class AotWithSpringDetector {
public static boolean useGeneratedArtifacts() {
return (NativeDetector.inNativeImage() || SpringProperties.getFlag(AOT_ENABLED));
}

public static boolean isAotProcessing() {
return (NativeDetector.inNativeImage() || SpringProperties.getFlag(AOT_PROCESSING));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.Constants;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
import org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent;
import org.apache.dubbo.config.spring.reference.ReferenceAttributes;
import org.apache.dubbo.config.spring.reference.ReferenceBeanManager;
Expand Down Expand Up @@ -545,6 +547,9 @@ public String registerReferenceBean(
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_CLASS, interfaceClass);
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_NAME, interfaceName);

if (AotWithSpringDetector.isAotProcessing()) {
beanDefinition.getPropertyValues().add("referencePropsJson", JsonUtils.toJson(attributes));
}
// create decorated definition for reference bean, Avoid being instantiated when getting the beanType of
// ReferenceBean
// see org.springframework.beans.factory.support.AbstractBeanFactory#getTypeForFactoryBean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.AnnotationUtils;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.Constants;
Expand Down Expand Up @@ -486,7 +487,13 @@ private AbstractBeanDefinition buildServiceBeanDefinition(
// Add methods parameters
List<MethodConfig> methodConfigs = convertMethodConfigs(serviceAnnotationAttributes.get("methods"));
if (!methodConfigs.isEmpty()) {
builder.addPropertyValue("methods", methodConfigs);
if (AotWithSpringDetector.isAotProcessing()) {
List<String> methodsJson = new ArrayList<>();
methodConfigs.forEach(methodConfig -> methodsJson.add(JsonUtils.toJson(methodConfig)));
builder.addPropertyValue("methodsJson", methodsJson);
} else {
builder.addPropertyValue("methods", methodConfigs);
}
}

// convert provider to providerIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.dubbo.config.annotation.ProvidedBy;
import org.apache.dubbo.config.spring.Constants;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
import org.apache.dubbo.config.spring.util.AnnotationUtils;
import org.apache.dubbo.config.spring.util.DubboAnnotationUtils;
import org.apache.dubbo.rpc.service.GenericService;
Expand Down Expand Up @@ -134,12 +133,7 @@ public static void convertReferenceProps(Map<String, Object> attributes, Class d

public static String generateReferenceKey(Map<String, Object> attributes, ApplicationContext applicationContext) {

String interfaceClass;
if (AotWithSpringDetector.useGeneratedArtifacts()) {
interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE_NAME);
} else {
interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE);
}
String interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE);
Assert.notEmptyString(interfaceClass, "No interface class or name found from attributes");
String group = (String) attributes.get(ReferenceAttributes.GROUP);
String version = (String) attributes.get(ReferenceAttributes.VERSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* @see DubboRelaxedBindingAutoConfiguration
* @since 2.7.0
*/
@Configuration
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true)
@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
@AutoConfigureBefore(DubboRelaxedBindingAutoConfiguration.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class DubboAutoConfiguration {
@ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnBean(name = BASE_PACKAGES_BEAN_NAME)
@Bean
public ServiceAnnotationPostProcessor serviceAnnotationBeanProcessor(
public static ServiceAnnotationPostProcessor serviceAnnotationBeanProcessor(
@Qualifier(BASE_PACKAGES_BEAN_NAME) Set<String> packagesToScan) {
ServiceAnnotationPostProcessor serviceAnnotationPostProcessor;
try {
Expand Down

0 comments on commit 00e4d60

Please sign in to comment.