本文许多内容来源于http://dubbo.io/Developer+Guide-zh.htm#DeveloperGuide-zh-%E8%B0%83%E7%94%A8%E9%93%BE,感谢作者的分享。
dubbo的整体架构图中包括了很多内容,这里只分析服务暴露部份。
针对服务暴露,对上面的图做了些简化
时序图
分成6个阶段,下面分别列出每一个阶段的调用堆栈。
1 初始化接口invoker
JavassistProxyFactory.getInvoker(T, Class<T>, URL) line: 40
StubProxyFactoryWrapper.getInvoker(T, Class<T>, URL) line: 104
ProxyFactory$Adpative.getInvoker(Object, Class, URL) line: not available
ServiceBean<T>(ServiceConfig<T>).exportLocal(URL) line: 516
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 469
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145
2 初始化exporter
DubboExporter<T>.<init>(Invoker<T>, String, Map<String,Exporter<?>>) line: 36
DubboProtocol.export(Invoker<T>) line: 240
ProtocolFilterWrapper.export(Invoker<T>) line: 55
ProtocolListenerWrapper.export(Invoker<T>) line: 56
Protocol$Adpative.export(Invoker) line: not available
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 495
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145
3 初始化server
DubboProtocol.createServer(URL) line: 318
DubboProtocol.openServer(URL) line: 308
DubboProtocol.export(Invoker<T>) line: 258
ProtocolFilterWrapper.export(Invoker<T>) line: 55
ProtocolListenerWrapper.export(Invoker<T>) line: 56
Protocol$Adpative.export(Invoker) line: not available
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 495
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145
4 绑定transporter
NettyTransporter.bind(URL, ChannelHandler) line: 33
Transporter$Adpative.bind(URL, ChannelHandler) line: not available
Transporters.bind(URL, ChannelHandler...) line: 48
HeaderExchanger.bind(URL, ExchangeHandler) line: 41
Exchangers.bind(URL, ExchangeHandler) line: 63
DubboProtocol.createServer(URL) line: 329
DubboProtocol.openServer(URL) line: 308
DubboProtocol.export(Invoker<T>) line: 258
ProtocolListenerWrapper.export(Invoker<T>) line: 56
ProtocolFilterWrapper.export(Invoker<T>) line: 55
Protocol$Adpative.export(Invoker) line: not available
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 495
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145
5 初始化codec
NettyServer(AbstractEndpoint).<init>(URL, ChannelHandler) line: 47
NettyServer(AbstractServer).<init>(URL, ChannelHandler) line: 59
NettyServer.<init>(URL, ChannelHandler) line: 63
NettyTransporter.bind(URL, ChannelHandler) line: 33
Transporter$Adpative.bind(URL, ChannelHandler) line: not available
Transporters.bind(URL, ChannelHandler...) line: 48
HeaderExchanger.bind(URL, ExchangeHandler) line: 41
Exchangers.bind(URL, ExchangeHandler) line: 63
DubboProtocol.createServer(URL) line: 329
DubboProtocol.openServer(URL) line: 308
DubboProtocol.export(Invoker<T>) line: 258
ProtocolListenerWrapper.export(Invoker<T>) line: 56
ProtocolFilterWrapper.export(Invoker<T>) line: 55
Protocol$Adpative.export(Invoker) line: not available
RegistryProtocol.doLocalExport(Invoker<T>) line: 153
RegistryProtocol.export(Invoker<T>) line: 107
ProtocolListenerWrapper.export(Invoker<T>) line: 54
ProtocolFilterWrapper.export(Invoker<T>) line: 53
Protocol$Adpative.export(Invoker) line: not available
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 489
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145
6 初始化channelHandler
AllChannelHandler(WrappedChannelHandler).<init>(ChannelHandler, URL) line: 47 //-----------⑹
AllChannelHandler.<init>(ChannelHandler, URL) line: 32
AllDispatcher.dispatch(ChannelHandler, URL) line: 32
Dispatcher$Adpative.dispatch(ChannelHandler, URL) line: not available
ChannelHandlers.wrapInternal(ChannelHandler, URL) line: 40
ChannelHandlers.wrap(ChannelHandler, URL) line: 33
NettyServer.<init>(URL, ChannelHandler) line: 63 //-----------------⑸
NettyTransporter.bind(URL, ChannelHandler) line: 33 //------------------⑷
Transporter$Adpative.bind(URL, ChannelHandler) line: not available
Transporters.bind(URL, ChannelHandler...) line: 48
HeaderExchanger.bind(URL, ExchangeHandler) line: 41
Exchangers.bind(URL, ExchangeHandler) line: 63
DubboProtocol.createServer(URL) line: 329 //---------------------⑶
DubboProtocol.openServer(URL) line: 308
DubboProtocol.export(Invoker<T>) line: 258
ProtocolFilterWrapper.export(Invoker<T>) line: 55
ProtocolListenerWrapper.export(Invoker<T>) line: 56
Protocol$Adpative.export(Invoker) line: not available
RegistryProtocol.doLocalExport(Invoker<T>) line: 153
RegistryProtocol.export(Invoker<T>) line: 107
ProtocolFilterWrapper.export(Invoker<T>) line: 53
ProtocolListenerWrapper.export(Invoker<T>) line: 54 //-----------------⑵
Protocol$Adpative.export(Invoker) line: not available
ServiceBean<T>(ServiceConfig<T>).doExportUrlsFor1Protocol(ProtocolConfig, List<URL>) line: 489 //------------⑴
ServiceBean<T>(ServiceConfig<T>).doExportUrls() line: 285
ServiceBean<T>(ServiceConfig<T>).doExport() line: 246
ServiceBean<T>(ServiceConfig<T>).export() line: 145