Search in sources :

Example 11 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ServiceClassPostProcessor method buildServiceBeanDefinition.

/**
 * Build the {@link AbstractBeanDefinition Bean Definition}
 *
 * @param serviceAnnotation
 * @param serviceAnnotationAttributes
 * @param interfaceClass
 * @param annotatedServiceBeanName
 * @return
 * @since 2.7.3
 */
private AbstractBeanDefinition buildServiceBeanDefinition(Annotation serviceAnnotation, AnnotationAttributes serviceAnnotationAttributes, Class<?> interfaceClass, String annotatedServiceBeanName) {
    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceBean.class);
    AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
    String[] ignoreAttributeNames = of("provider", "monitor", "application", "module", "registry", "protocol", "interface", "interfaceName", "parameters");
    propertyValues.addPropertyValues(new AnnotationPropertyValuesAdapter(serviceAnnotation, environment, ignoreAttributeNames));
    // References "ref" property to annotated-@Service Bean
    addPropertyReference(builder, "ref", annotatedServiceBeanName);
    // Set interface
    builder.addPropertyValue("interface", interfaceClass.getName());
    // Convert parameters into map
    builder.addPropertyValue("parameters", DubboAnnotationUtils.convertParameters(serviceAnnotationAttributes.getStringArray("parameters")));
    // Add methods parameters
    List<MethodConfig> methodConfigs = convertMethodConfigs(serviceAnnotationAttributes.get("methods"));
    if (!methodConfigs.isEmpty()) {
        builder.addPropertyValue("methods", methodConfigs);
    }
    /**
     * Add {@link org.apache.dubbo.config.ProviderConfig} Bean reference
     */
    String providerConfigBeanName = serviceAnnotationAttributes.getString("provider");
    if (StringUtils.hasText(providerConfigBeanName)) {
        addPropertyReference(builder, "provider", providerConfigBeanName);
    }
    /**
     * Add {@link org.apache.dubbo.config.MonitorConfig} Bean reference
     */
    String monitorConfigBeanName = serviceAnnotationAttributes.getString("monitor");
    if (StringUtils.hasText(monitorConfigBeanName)) {
        addPropertyReference(builder, "monitor", monitorConfigBeanName);
    }
    /**
     * Add {@link org.apache.dubbo.config.ApplicationConfig} Bean reference
     */
    String applicationConfigBeanName = serviceAnnotationAttributes.getString("application");
    if (StringUtils.hasText(applicationConfigBeanName)) {
        addPropertyReference(builder, "application", applicationConfigBeanName);
    }
    /**
     * Add {@link org.apache.dubbo.config.ModuleConfig} Bean reference
     */
    String moduleConfigBeanName = serviceAnnotationAttributes.getString("module");
    if (StringUtils.hasText(moduleConfigBeanName)) {
        addPropertyReference(builder, "module", moduleConfigBeanName);
    }
    /**
     * Add {@link org.apache.dubbo.config.RegistryConfig} Bean reference
     */
    String[] registryConfigBeanNames = serviceAnnotationAttributes.getStringArray("registry");
    List<RuntimeBeanReference> registryRuntimeBeanReferences = toRuntimeBeanReferences(registryConfigBeanNames);
    if (!registryRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("registries", registryRuntimeBeanReferences);
    }
    /**
     * Add {@link org.apache.dubbo.config.ProtocolConfig} Bean reference
     */
    String[] protocolConfigBeanNames = serviceAnnotationAttributes.getStringArray("protocol");
    List<RuntimeBeanReference> protocolRuntimeBeanReferences = toRuntimeBeanReferences(protocolConfigBeanNames);
    if (!protocolRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("protocols", protocolRuntimeBeanReferences);
    }
    return builder.getBeanDefinition();
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 12 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class InvokerSideConfigUrlTest method initRefConf.

// ======================================================
// private helper
// ======================================================
private void initRefConf() {
    regConfForConsumer = new RegistryConfig();
    regConfForReference = new RegistryConfig();
    methodConfForReference = new MethodConfig();
    refConf = new ReferenceConfig<DemoService>();
    consumerConf = new ConsumerConfig();
    methodConfForReference.setName("sayName");
    regConfForReference.setAddress("127.0.0.1:9090");
    regConfForReference.setProtocol("mockregistry");
    refConf.setInterface("org.apache.dubbo.config.api.DemoService");
    refConf.setApplication(application);
    // consumerConf.setApplication(appConfForConsumer);
    refConf.setRegistry(regConfForReference);
    consumerConf.setRegistry(regConfForConsumer);
    refConf.setConsumer(consumerConf);
    refConf.setMethods(Arrays.asList(new MethodConfig[] { methodConfForReference }));
    refConf.setScope(SCOPE_REMOTE);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) MethodConfig(org.apache.dubbo.config.MethodConfig) DemoService(org.apache.dubbo.config.api.DemoService) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig)

Example 13 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class MethodBuilder method build.

public MethodConfig build() {
    MethodConfig methodConfig = new MethodConfig();
    super.build(methodConfig);
    methodConfig.setArguments(arguments);
    methodConfig.setDeprecated(deprecated);
    methodConfig.setExecutes(executes);
    methodConfig.setName(name);
    methodConfig.setOninvoke(oninvoke);
    methodConfig.setOninvokeMethod(oninvokeMethod);
    methodConfig.setOnreturn(onreturn);
    methodConfig.setOnreturnMethod(onreturnMethod);
    methodConfig.setOnthrow(onthrow);
    methodConfig.setOnthrowMethod(onthrowMethod);
    methodConfig.setReturn(isReturn);
    methodConfig.setService(service);
    methodConfig.setServiceId(serviceId);
    methodConfig.setSticky(sticky);
    methodConfig.setReliable(reliable);
    methodConfig.setStat(stat);
    methodConfig.setRetry(retry);
    return methodConfig;
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig)

Aggregations

MethodConfig (org.apache.dubbo.config.MethodConfig)13 Test (org.junit.jupiter.api.Test)7 RegistryConfig (org.apache.dubbo.config.RegistryConfig)3 DemoService (org.apache.dubbo.config.api.DemoService)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)2 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ProviderConfig (org.apache.dubbo.config.ProviderConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 ServiceConfig (org.apache.dubbo.config.ServiceConfig)2 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 ArgumentConfig (org.apache.dubbo.config.ArgumentConfig)1 Method (org.apache.dubbo.config.annotation.Method)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1