Netty源码实战(十一) - 设计模式的应用

1 单例模式

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

1.1 Netty 实例

1.1.1 ReadTimeoutException

Netty源码实战(十一) - 设计模式的应用
可以看出,构造器私有,防止随意创建
static保证延迟加载

1.1.2 MqttEncoder

Netty源码实战(十一) - 设计模式的应用

2 策略模式

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

Netty源码实战(十一) - 设计模式的应用

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

3 装饰者模式

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

Netty 实践

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

4 观察者模式

4.1 常规操作

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用

4.2 Netty 的实践

  • 在调用 writeAndFlush 后,其实返回的就是被观察者ChannelFultureNetty源码实战(十一) - 设计模式的应用
  • 添加观察者
    Netty源码实战(十一) - 设计模式的应用
    Netty源码实战(十一) - 设计模式的应用
    下面让我们深入writeAndFlush 看看
  • 从 pipeline 开始传播
    Netty源码实战(十一) - 设计模式的应用
  • 从 tail节点从后往前进行传播
    Netty源码实战(十一) - 设计模式的应用
  • promise就是被观察者
    Netty源码实战(十一) - 设计模式的应用
    Netty源码实战(十一) - 设计模式的应用
    Netty源码实战(十一) - 设计模式的应用
    下面看看添加观察者的源码实现~
    Netty源码实战(十一) - 设计模式的应用
    Netty源码实战(十一) - 设计模式的应用
    Netty源码实战(十一) - 设计模式的应用

3 迭代器模式

Netty源码实战(十一) - 设计模式的应用

  • 示例Netty源码实战(十一) - 设计模式的应用

4 责任链模式

Netty源码实战(十一) - 设计模式的应用
Netty源码实战(十一) - 设计模式的应用