欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Dubbo 源码阅读(六)ServiceBean

程序员文章站 2022-06-01 13:41:16
...

服务暴露的过程

Dubbo 源码阅读(六)ServiceBean

源码

过长的源码省略了,看重点

afterPropertiesSet() -> export()

@Override
public void export() {
    super.export();
    // Publish ServiceBeanExportedEvent
    publishExportEvent();
}

跟 export:
类 ServiceConfig

public synchronized void export() {
   if (provider != null) {
       if (export == null) {
           export = provider.getExport();
       }
       if (delay == null) {
           delay = provider.getDelay();
       }
   }
   if (export != null && !export) {
       return;
   }

   if (delay != null && delay > 0) {
       delayExportExecutor.schedule(new Runnable() {
           @Override
           public void run() {
               doExport();
           }
       }, delay, TimeUnit.MILLISECONDS);
   } else {
       doExport();
   }
}

跟 doExport() -> doExportUrls()

private void doExportUrls() {
    List<URL> registryURLs = loadRegistries(true);
    //对每一个协议暴露
    for (ProtocolConfig protocolConfig : protocols) {
        doExportUrlsFor1Protocol(protocolConfig, registryURLs);
    }
}

跟 doExportUrlsFor1Protocol:

//...
//包装成服务实例                               ServiceBean的目标属性        网络协议的URL
Invoker<?> invoker = proxyFactory.getInvoker(ref, (Class) interfaceClass, registryURL.addParameterAndEncoded(Constants.EXPORT_KEY, url.toFullString()));
DelegateProviderMetaDataInvoker wrapperInvoker = new DelegateProviderMetaDataInvoker(invoker, this);
Exporter<?> exporter = protocol.export(wrapperInvoker);//暴露服务
exporters.add(exporter);
//...
相关标签: Dubbo