大家可以把这个也下载下来,结合之前的Nacos一起来看下,感觉前面几篇看了好像冰山一角的感觉

学无止境!

https://github.com/nacos-group/nacos-spring-project

其实前面的很多猜测都是在这个里面去实现的;这个明天再系统的去看吧;

把之前的问题给大家补上,就是EventDispatcher.java如何初始化的

    static final CopyOnWriteArrayList<Entry> LISTENER_HUB = new CopyOnWriteArrayList<Entry>();

这里给大家看下一个小方法,我自己写的

public abstract class AbstractEventListener {
// 抽象类中定义一个构造方法
public AbstractEventListener(){
System.out.println("print abstract constractor init");
} static class AsyncNotifyService extends AbstractEventListener{
private String serviceName ;
// 子类中自定义构造函数
public AsyncNotifyService(String serviceName){
System.out.println("print class AsyncNotifyService constractor init");
this.serviceName = serviceName;
}
}
// 子类中在自定义构造函数
static class LongPollingService extends AbstractEventListener {
public LongPollingService() {
System.out.println("print class LongPollingService constractor init");
}
} public static void main(String[] args){
AsyncNotifyService asyncNotifyService = new AsyncNotifyService("123");
LongPollingService longPollingService = new LongPollingService();
}
}

其实这个不管父类是抽象类还是具体某个类,子类在继承的时候都会先调用父类中的构造函数,然后再执行子类中的构造函数;

下面贴下结果:

这样再回去看Nacos的方法就能明白了

public class LongPollingService extends AbstractEventListener {}
public class AsyncNotifyService extends AbstractEventListener {}

在每个子类的Service中,都有构造函数,在构造函数中进行了初始化,初始化了LISTENER_HUB ;
这样就完成了; 明天继续给大家写!

最新文章

  1. 【hive】——Hive基本操作
  2. iOS - SQLite 数据库存储
  3. C++ 引用
  4. Python基础4- 字符串
  5. 高性能MySQL --- 读书笔记(1) - 2016/8/2
  6. 在MVC中如何愉快使用Ajax
  7. LinqToXML~读XML文件续
  8. 开源欣赏wordpress之用户新增user-new.php
  9. Unable to open connection to supplicant on &quot;/data/misc/wifi/sockets/wlan0&quot;
  10. Java实现CORS跨域请求
  11. MySQL执行一个查询的过程
  12. 2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口
  13. STM32F0使用LL库实现MS5536C通讯
  14. sqlserver开窗函数在财务对账中的用法
  15. Python之多线程和多进程
  16. JS中的跨域问题
  17. codeforces510B
  18. RedHat如何关闭防火墙&#160;:&#160;http://blog.csdn.net/chongxin1/article/details/76072758
  19. Android开发——Android多进程以及使用场景介绍
  20. vue中assets和static的区别

热门文章

  1. nodejs中的子进程,深入解析child_process模块和cluster模块
  2. Linux系统资源查看与设置
  3. Ubuntu 更新/安装nodejs
  4. Collaborative Index Embedding for Image Retrieval
  5. [acm]HDOJ 2673 shǎ崽 OrOrOrOrz
  6. WPF TreeView 后台C#选中指定的Item, 需要遍历
  7. TI官网常用链接
  8. ActiveRecord 的类型初始值设定项引发异常
  9. deleteMany is not a function
  10. JavaScript高级程序设计学习笔记第三章--基本概念