com.alibaba.dubbo.config.AbstractConfig Java Examples

The following examples show how to use com.alibaba.dubbo.config.AbstractConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DubboConfigBindingRegistrar.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void registerDubboConfigBeans(String prefix,
                                          Class<? extends AbstractConfig> configClass,
                                          boolean multiple,
                                          BeanDefinitionRegistry registry) {

        Map<String, Object> properties = getSubProperties(environment.getPropertySources(), prefix);

        if (CollectionUtils.isEmpty(properties)) {
            if (log.isDebugEnabled()) {
                log.debug("There is no property for binding to dubbo config class [" + configClass.getName()
                        + "] within prefix [" + prefix + "]");
            }
            return;
        }

        Set<String> beanNames = multiple ? resolveMultipleBeanNames(properties) :
                Collections.singleton(resolveSingleBeanName(properties, configClass, registry));

        for (String beanName : beanNames) {

//            注册dubbo配置bean定义=》
            registerDubboConfigBean(beanName, configClass, registry);

//            注册dubbo配置绑定bean处理器=》
            registerDubboConfigBindingBeanPostProcessor(prefix, beanName, multiple, registry);

        }

    }
 
Example #2
Source File: DefaultDubboConfigBinder.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) {
    DataBinder dataBinder = new DataBinder(dubboConfig);
    // Set ignored*
    dataBinder.setIgnoreInvalidFields(isIgnoreInvalidFields());
    dataBinder.setIgnoreUnknownFields(isIgnoreUnknownFields());
    // Get properties under specified prefix from PropertySources
    Map<String, Object> properties = getSubProperties(getPropertySources(), prefix);
    // Convert Map to MutablePropertyValues
    MutablePropertyValues propertyValues = new MutablePropertyValues(properties);
    // Bind
    dataBinder.bind(propertyValues);
}
 
Example #3
Source File: DubboConfigBindingBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        if (beanName.equals(this.beanName) && bean instanceof AbstractConfig) {

            AbstractConfig dubboConfig = (AbstractConfig) bean;

//            进行dubbo配置绑定=》
            dubboConfigBinder.bind(prefix, dubboConfig);

            if (log.isInfoEnabled()) {
                log.info("The properties of bean [name : " + beanName + "] have been binding by prefix of " +
                        "configuration properties : " + prefix);
            }
        }

        return bean;

    }
 
Example #4
Source File: DubboConfigBindingRegistrar.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
protected void registerBeanDefinitions(AnnotationAttributes attributes, BeanDefinitionRegistry registry) {

//        解析prefix属性,可以用占位符
        String prefix = environment.resolvePlaceholders(attributes.getString("prefix"));

//        type属性值,AbstractConfig的实现类
        Class<? extends AbstractConfig> configClass = attributes.getClass("type");

        boolean multiple = attributes.getBoolean("multiple");

//        注册dubbo配置属性=》
        registerDubboConfigBeans(prefix, configClass, multiple, registry);

    }
 
Example #5
Source File: DubboConfigBindingRegistrar.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
private void registerDubboConfigBean(String beanName, Class<? extends AbstractConfig> configClass,
                                     BeanDefinitionRegistry registry) {

    BeanDefinitionBuilder builder = rootBeanDefinition(configClass);

    AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

    registry.registerBeanDefinition(beanName, beanDefinition);

    if (log.isInfoEnabled()) {
        log.info("The dubbo config bean definition [name : " + beanName + ", class : " + configClass.getName() +
                "] has been registered.");
    }

}
 
Example #6
Source File: DubboConfigBindingRegistrar.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
private String resolveSingleBeanName(Map<String, Object> properties, Class<? extends AbstractConfig> configClass,
                                     BeanDefinitionRegistry registry) {

    String beanName = (String) properties.get("id");

    if (!StringUtils.hasText(beanName)) {
        BeanDefinitionBuilder builder = rootBeanDefinition(configClass);
        beanName = BeanDefinitionReaderUtils.generateBeanName(builder.getRawBeanDefinition(), registry);
    }

    return beanName;

}
 
Example #7
Source File: DubboConfigBinder.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * Bind the properties to Dubbo Config Object under specified prefix.将属性绑定到指定前缀下的Dubbo配置对象。
 *
 * @param prefix
 * @param dubboConfig
 */
<C extends AbstractConfig> void bind(String prefix, C dubboConfig);