In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how is the process of dubbo initialization parsing bean". In daily operation, I believe many people have doubts about the process of dubbo initialization parsing bean. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how is the process of dubbo initialization parsing bean?" Next, please follow the editor to study!
Parsing service
Based on the META-INF/spring.handlers configuration within dubbo.jar, Spring calls back DubboNamespaceHandler when it encounters the dubbo namespace.
All dubbo tags are parsed using DubboBeanDefinitionParser, and XML tags are parsed into Bean objects based on one-to-one attribute mapping.
When ServiceConfig.export () or ReferenceConfig.get () initializes, the Bean object is converted to URL format, and all Bean properties are converted to parameters of URL.
Then the URL is passed to the Protocol extension point, and based on the Adaptive mechanism of the extension point, the services of different protocols are exposed or referenced according to the protocol header of URL.
The exposure of the dubbo service invokes the ServiceConfig.export () code as follows:
Com.alibaba.dubbo.config.ServiceConfig#export
/ / expose service
Public synchronized void export () {
If (provider! = null) {
If (export = = null) {
Export = provider.getExport ()
}
If (delay = = null) {
Delay = provider.getDelay ()
}
}
If (export! = null & &! Export.booleanValue () {
Return
}
If (delay! = null & & delay > 0) {
Thread thread = new Thread (new Runnable () {
Public void run () {
Try {
Thread.sleep (delay)
} catch (Throwable e) {
}
DoExport ()
}
});
Thread.setDaemon (true)
Thread.setName ("DelayExportServiceThread")
Thread.start ()
} else {
DoExport ()
}
}
When you look at the export call chain, you can see that this method is called in two places:
1. Com.alibaba.dubbo.config.spring.AnnotationBean#postProcessAfterInitialization: when the way of annotation is exposed
2. Com.alibaba.dubbo.config.spring.ServiceBean#afterPropertiesSet: when exposed as a spring configuration file
Inheritance relationship of AnnotationBean class
Public class AnnotationBean extends AbstractConfig implements DisposableBean, BeanFactoryPostProcessor, BeanPostProcessor, ApplicationContextAware {
AnnotationBean implements the interfaces related to spring bean and context, and calls the export () method to expose the service after spring scans the annotation class and parses it.
ServiceBean
Public class ServiceBean extends ServiceConfig implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener, BeanNameAware {
After the spring initialization parsing bean is completed, the export () is mainly performed after the parsing of the spring tag, the definition of bean, the attribute parsing setting of bean, etc.
Because dubbo is its own custom tag, the parsing of bean is the most important part before export. Today, instead of looking at the service exposure, let's look at dubbo's resolution of services. There are two important classes:
Com.alibaba.dubbo.config.spring.schema.DubboNamespaceHandler
Com.alibaba.dubbo.config.spring.schema.DubboBeanDefinitionParser#parse
The following is the DubboNamespaceHandler code, with my comments (my own understanding)
Public class DubboNamespaceHandler extends NamespaceHandlerSupport {
Static {
/ * *
* retrieve whether there is a duplicate namespace processor
, /
Version.checkDuplicate (DubboNamespaceHandler.class)
}
Public void init () {
/ * *
* sign up for bean. The real negative resolution is DubboBeanDefinitionParser.
* DubboBeanDefinitionParser will parse all attributes and put attribute values into BeanDefinition
, /
RegisterBeanDefinitionParser ("application", new DubboBeanDefinitionParser (ApplicationConfig.class, true))
RegisterBeanDefinitionParser ("module", new DubboBeanDefinitionParser (ModuleConfig.class, true))
RegisterBeanDefinitionParser ("registry", new DubboBeanDefinitionParser (RegistryConfig.class, true))
RegisterBeanDefinitionParser ("monitor", new DubboBeanDefinitionParser (MonitorConfig.class, true))
RegisterBeanDefinitionParser ("provider", new DubboBeanDefinitionParser (ProviderConfig.class, true))
RegisterBeanDefinitionParser ("consumer", new DubboBeanDefinitionParser (ConsumerConfig.class, true))
RegisterBeanDefinitionParser ("protocol", new DubboBeanDefinitionParser (ProtocolConfig.class, true))
RegisterBeanDefinitionParser ("service", new DubboBeanDefinitionParser (ServiceBean.class, true))
RegisterBeanDefinitionParser ("reference", new DubboBeanDefinitionParser (ReferenceBean.class, false))
RegisterBeanDefinitionParser ("annotation", new DubboBeanDefinitionParser (AnnotationBean.class, true))
}
}
All the parsing work is in DubboBeanDefinitionParser; for more information, please see DubboBeanDefinitionParser
The ultimate goal of parsing is to return the RootBeanDefinition object. RootBeanDefinition contains all the information about bean. Note that after the parsing of bean, it is only spring that converts it into an abstract data object structure within spring. The creation (instantiation) of bean is created when getBean is called for the first time. The above is the process of parsing configuration files and service definitions by dubbo. The exposure of the dubbo service is written later.
At this point, the study of "what is the process of dubbo initialization parsing bean" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.