Netty解析五:SelectStrategyFactory及其实现
同样的在构造器中看到了SelectStrategyFactory参数,所以先对SelectStrategyFactory类进行解析。
解析
SelectStrategyFactory接口
SelectStrategyFactory接口功能十分简单就是生产Select策略。1
2
3
4
5
6public interface SelectStrategyFactory {
/**
* Creates a new {@link SelectStrategy}.
*/
SelectStrategy newSelectStrategy();
}
实现类DefaultSelectStrategyFactory
目前只有一个实现类DefaultSelectStrategyFactory。
DefaultSelectStrategyFactory是一个单例类,同时它生产的Select策略也是单例类(DefaultSelectStrategy)。
1 | public final class DefaultSelectStrategyFactory implements SelectStrategyFactory { |
SelectStrategy接口
SelectStrategy提供了控制select循环的能力,比如:
如果有事件要立即处理,一个堵塞的select操作能够被延迟或者完全停止。
1 | public interface SelectStrategy { |
实现类DefaultSelectStrategy
和DefaultSelectStrategyFactory一样也是一个单例类,它的实现非常简单:有任务的时候交由传入的IntSupplier类实现,不然直接返回SelectStrategy.SELECT。
1 | final class DefaultSelectStrategy implements SelectStrategy { |