1 单例模式

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

1.1 Netty 实例

1.1.1 ReadTimeoutException

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

1.1.2 MqttEncoder

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

2 策略模式

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

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

Netty源码实战(十一) - 设计模式的应用_网络_08
Netty源码实战(十一) - 设计模式的应用_源码_09
Netty源码实战(十一) - 设计模式的应用_netty_10

3 装饰者模式

Netty源码实战(十一) - 设计模式的应用_网络_11
Netty源码实战(十一) - 设计模式的应用_java_12

Netty 实践

Netty源码实战(十一) - 设计模式的应用_ 面试_13
Netty源码实战(十一) - 设计模式的应用_netty_14
Netty源码实战(十一) - 设计模式的应用_源码_15
Netty源码实战(十一) - 设计模式的应用_源码_16

4 观察者模式

4.1 常规操作

Netty源码实战(十一) - 设计模式的应用_源码_17
Netty源码实战(十一) - 设计模式的应用_网络_18
Netty源码实战(十一) - 设计模式的应用_网络_19
Netty源码实战(十一) - 设计模式的应用_源码_20
Netty源码实战(十一) - 设计模式的应用_java_21
Netty源码实战(十一) - 设计模式的应用_java_22

4.2 Netty 的实践

  • 在调用 writeAndFlush 后,其实返回的就是被观察者ChannelFultureNetty源码实战(十一) - 设计模式的应用_netty_23
  • 添加观察者
    Netty源码实战(十一) - 设计模式的应用_netty_24
    Netty源码实战(十一) - 设计模式的应用_网络_25
    下面让我们深入writeAndFlush 看看
  • 从 pipeline 开始传播
    Netty源码实战(十一) - 设计模式的应用_java_26
  • 从 tail节点从后往前进行传播
    Netty源码实战(十一) - 设计模式的应用_java_27
  • promise就是被观察者
    Netty源码实战(十一) - 设计模式的应用_源码_28
    Netty源码实战(十一) - 设计模式的应用_netty_29
    Netty源码实战(十一) - 设计模式的应用_netty_30
    下面看看添加观察者的源码实现~
    Netty源码实战(十一) - 设计模式的应用_java_31
    Netty源码实战(十一) - 设计模式的应用_源码_32
    Netty源码实战(十一) - 设计模式的应用_源码_33
3 迭代器模式

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

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

Netty源码实战(十一) - 设计模式的应用_源码_36
Netty源码实战(十一) - 设计模式的应用_ 面试_37