1. protected synchronized void doExport() {
    //如果是已经解除暴露的接口则抛出异常
  2. if (unexported) {
  3. throw new IllegalStateException("Already unexported!");
  4. }
         //如果已经暴露则不需要重复暴露 
  5. if (exported) {
  6. return;
  7. }
  8. exported = true;
  9. if (interfaceName == null || interfaceName.length() == 0) {
  10. throw new IllegalStateException("<dubbo:service interface=\"\" /> interface not allow null!");
  11. }
  12. checkDefault();
  13. if (provider != null) {
  14. if (application == null) {
  15. application = provider.getApplication();
  16. }
  17. if (module == null) {
  18. module = provider.getModule();
  19. }
  20. if (registries == null) {
  21. registries = provider.getRegistries();
  22. }
  23. if (monitor == null) {
  24. monitor = provider.getMonitor();
  25. }
  26. if (protocols == null) {
  27. protocols = provider.getProtocols();
  28. }
  29. }
  30. if (module != null) {
  31. if (registries == null) {
  32. registries = module.getRegistries();
  33. }
  34. if (monitor == null) {
  35. monitor = module.getMonitor();
  36. }
  37. }
  38. if (application != null) {
  39. if (registries == null) {
  40. registries = application.getRegistries();
  41. }
  42. if (monitor == null) {
  43. monitor = application.getMonitor();
  44. }
  45. }
    // ref是接口实现类引用,GenericService是泛接口,这个方式主要用于服务器端没有API接口及模型类元的情况,参数及返回值中的所有POJO均用Map表示,通常用于框架集成,比如:实现一个通用的远程服务Mock框架,可通过实现GenericService接口处理所有服务请求。
  46. if (ref instanceof GenericService) {
  47. interfaceClass = GenericService.class;
  48. if (StringUtils.isEmpty(generic)) {
  49. generic = Boolean.TRUE.toString();
  50. }
  51. } else {
  52. try {
  53. interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
  54. .getContextClassLoader());
  55. } catch (ClassNotFoundException e) {
  56. throw new IllegalStateException(e.getMessage(), e);
  57. }
  58. checkInterfaceAndMethods(interfaceClass, methods);
  59. checkRef();
  60. generic = Boolean.FALSE.toString();
  61. }
         //local属性已被弃用,由stub属性替代
  62. if(local !=null){
  63. if(local=="true"){
  64. local=interfaceName+"Local";
  65. }
  66. Class<?> localClass;
  67. try {
  68. localClass = ClassHelper.forNameWithThreadContextClassLoader(local);
  69. } catch (ClassNotFoundException e) {
  70. throw new IllegalStateException(e.getMessage(), e);
  71. }
  72. if(!interfaceClass.isAssignableFrom(localClass)){
  73. throw new IllegalStateException("The local implemention class " + localClass.getName() + " not implement interface " + interfaceName);
  74. }
  75. }
    //stub设为true,表示使用缺省代理类名,即:接口名 + Local后缀,服务接口客户端本地代理类名,用于在客户端执行本地逻辑,如本地缓存等,该本地代理类的构造函数必须允许传入远程代理对象,构造函数如:public XxxServiceLocal(XxxService xxxService)
  76. if(stub !=null){
  77. if(stub=="true"){
  78. stub=interfaceName+"Stub";
  79. }
  80. Class<?> stubClass;
  81. try {
  82. stubClass = ClassHelper.forNameWithThreadContextClassLoader(stub);
  83. } catch (ClassNotFoundException e) {
  84. throw new IllegalStateException(e.getMessage(), e);
  85. }
  86. if(!interfaceClass.isAssignableFrom(stubClass)){
  87. throw new IllegalStateException("The stub implemention class " + stubClass.getName() + " not implement interface " + interfaceName);
  88. }
  89. }
  90. checkApplication();
  91. checkRegistry();
  92. checkProtocol();
  93. appendProperties(this);
  94. checkStubAndMock(interfaceClass);
  95. if (path == null || path.length() == 0) {
  96. path = interfaceName;
  97. }
  98. doExportUrls();
  99. }

在doExport方法中,对要暴露的服务进行了一系列的检查,检查provider,application,module,registries,monitor这些参数是否为空,是否是GenericService类型的服务,检查要注册的bean的引用和方法等。在方法的最后会调用doExportUrls方法。

dubbo源码分析11——服务暴露2_doExport()方法分析的更多相关文章

  1. dubbo源码分析10——服务暴露1_export()方法分析

    ServiceConfig类中的export()方法,是dubbo服务暴露的入口方法,被触发的时机有两个: 1. spring容器初始化完成所有的bean实例后,通过事件机制触发 2. 实现Initi ...

  2. dubbo源码分析12——服务暴露3_doExportUrls()方法分析

    本文紧接上文,doExportUrls()方法位于ServiceConfig类中,代码入口如下: private void doExportUrls() { List<URL> regis ...

  3. dubbo源码学习(四):暴露服务的过程

    dubbo采用的nio异步的通信,通信协议默认为 netty,当然也可以选择 mina,grizzy.在服务端(provider)在启动时主要是开启netty监听,在zookeeper上注册服务节点, ...

  4. Dubbo源码学习之-服务导出

    前言 忙的时候,会埋怨学习的时间太少,缺少个人的空间,于是会争分夺秒的工作.学习.而一旦繁忙的时候过去,有时间了之后,整个人又会不自觉的陷入一种懒散的状态中,时间也显得不那么重要了,随便就可以浪费掉几 ...

  5. [dubbo 源码之 ]1. 服务提供方如何发布服务

    服务发布 启动流程 1.ServiceConfig#export 服务提供方在启动部署时,dubbo会调用ServiceConfig#export来激活服务发布流程,如下所示: Java API: ` ...

  6. dubbo 源码学习1 服务发布机制

    1.源码版本:2.6.1 源码demo中采用的是xml式的发布方式,在dubbo的 DubboNamespaceHandler 中定义了Spring Framework 的扩展标签,即 <dub ...

  7. dubbo源码阅读之服务导出

    dubbo服务导出 常见的使用dubbo的方式就是通过spring配置文件进行配置.例如下面这样 <?xml version="1.0" encoding="UTF ...

  8. dubbo源码阅读之服务目录

    服务目录 服务目录对应的接口是Directory,这个接口里主要的方法是 List<Invoker<T>> list(Invocation invocation) throws ...

  9. dubbo源码阅读之服务引入

    服务引入 服务引入使用reference标签来对要引入的服务进行配置,包括服务的接口 ,名称,init,check等等配置属性. 在DubboNamespaceHandler中,我们可以看到refer ...

随机推荐

  1. 给笔记本更换SSD硬盘

    给笔记本更换SSD硬盘... ---------- 给笔记本更换SSD硬盘 带活动字样的一个新的系统盘,一个之前的主分区的系统盘 ----------------------------

  2. Oracle 数据库分页查询与排序分页查询

    一.分页查询 原始查询语句 SELECT * FROM NASLE_WFSHH 修改为分页查询语句,加上 ROWNUM 列.此处为查询第 1 页,每页 9 条数据 SELECT * FROM ( SE ...

  3. EL表达式遍历集合获取下标

    如题,HTML页面很多时候需要循环遍历一个集合,并且获得集合元素得下标做判断,或者把下标传递给后台作为参数 那么我们就需要用到EL表达式的varStatus 代码一:<c:forEach var ...

  4. jQuery源码解析对象实例化与jQuery原型及整体构建模型分析(一)

    //源码剖析都基于jQuery-2.0.3版本,主要考虑到兼容IE 一.关于jQuery对象实例化的逻辑: 整个jQuery程序被包裹在一个匿名自执行行数内: (function(window,und ...

  5. Spark Submitting Applications浅析

    Submitting Applications提交应用程序 在spark的bin目录下spark-submit脚本被用于在集群中启动应用程序.它可以通过一个统一的接口来使用Spark支持的所有集群管理 ...

  6. Android弹出窗口

    protected void PopUp() { final PopupWindow popup = new PopupWindow(TestActivity.this); View popView ...

  7. luogu 1268 树的重量

    打眼一看就是最小生成树嘛,但经过板子wa掉的经历后得知,,emmmm,原来是, 构造! (虽然不知是什么但觉得听起来很厉害的样子...手动微笑) n=2的情况 自然就是g(1,2) n=3的情况,由于 ...

  8. aspnetpager使用介绍

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化, 效果如下: 下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首 ...

  9. luogu P4385 [COCI2009]Dvapravca

    传送门 我真的弱,正解都不会还打了个错的暴力 考虑平行线与x轴平行,那么可以按照y为第一关键字升序,x为第二关键字升序排序,然后合法的一段红点就是连续的一段,答案也就是最大的连续红色段 推广到一般情况 ...

  10. Kaldi的BaseLine训练过程

    steps/train_mono.sh --nj "$train_nj" --cmd "$train_cmd" data/train data/lang exp ...