EventExecutor 在netty extends EventExecutorGroup 是不是一个好的设计?
Is it a good design that EventExecutor extends EventExecutorGroup in netty?
有两个类的符号:
/**
* 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
,对吧?(emmmm.. 还有 EventLoop
extends EventLoopGroup
也....)
为什么一个元素会扩展它的容器并将自己当作一个特殊的容器?
我想知道有没有我遗漏的优点
它基本上是因为 EventExecutor
只是 EventExecutorGroup
只包含它自己。此外,这还允许在需要通过和 EventExecutorGroup
的地方重新使用 EventExecutor
。
这在许多不同的情况下都很方便,例如它允许您创建一个 Bootstrap
并使用一个 EventLoop
作为它的 EventLoopGroup
从而确保所有 I/O 由同一个线程处理。这在构建代理时非常有用。
有两个类的符号:
/**
* 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
,对吧?(emmmm.. 还有 EventLoop
extends EventLoopGroup
也....)
为什么一个元素会扩展它的容器并将自己当作一个特殊的容器?
我想知道有没有我遗漏的优点
它基本上是因为 EventExecutor
只是 EventExecutorGroup
只包含它自己。此外,这还允许在需要通过和 EventExecutorGroup
的地方重新使用 EventExecutor
。
这在许多不同的情况下都很方便,例如它允许您创建一个 Bootstrap
并使用一个 EventLoop
作为它的 EventLoopGroup
从而确保所有 I/O 由同一个线程处理。这在构建代理时非常有用。