有两个类别的符号:
/**
* The {@link EventExecutor} is a special {@link EventExecutorGroup} which comes
* with some handy methods to see if a {@link Thread} is executed in a event loop.
* Besides this, it also extends the {@link EventExecutorGroup} to allow for a generic
* way to access methods.
*
*/
public interface EventExecutor extends EventExecutorGroup {
/**
* The {@link EventExecutorGroup} is responsible for providing the {@link EventExecutor}'s to use
* via its {@link #next()} method. Besides this, it is also responsible for handling their
* life-cycle and allows shutting them down in a global fashion.
*
*/
public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor> {
EventExecutorGroup
是EventExecutor
的容器,并管理其生命周期。没关系,而且很容易理解。
我认为设计目的主要是重用一些方法定义,并且感觉不太自然。没有人会做Thread extends ThreadPool
,对吗?(嗯。还有EventLoop
扩展了EventLoopGroup
....)
为什么元素扩展其容器并将其自身视为特殊容器?
我想知道我是否错过了一些优势。
答案 0 :(得分:1)
基本上和EventExecutor
一样,EventExecutorGroup
仅包含自身。此外,这还允许在需要通过EventExecutor
的地方重新使用EventExecutorGroup
。
这在许多情况下都很方便,例如,它允许您创建一个Bootstrap
并使用一个EventLoop
作为其EventLoopGroup
,从而确保处理所有I / O。通过同一线程。例如,当您构建代理时,这非常有用。