Netty2——EventExecutor
2016-04-08 13:26
344 查看
![](https://images2015.cnblogs.com/blog/709357/201604/709357-20160408111314656-2039941182.png)
EventExecutorGroup接口:
public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor> {
在ScheduleExecutorService和Iterable的基础上增加了以下接口:
boolean isShuttingDown(); Future<?> shutdownGracefully(); Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit); Future<?> terminationFuture(); EventExecutor next();
EventExecutorGroup继承Iterable接口表明他是一个EventExecutor容器。
EventExecutor接口:
public interface EventExecutor extends EventExecutorGroup {
在EventExecutorGroup的基础上增加了以下接口:
EventExecutorGroup parent(); boolean inEventLoop(); boolean inEventLoop(Thread thread); <V> Promise<V> newPromise(); <V> ProgressivePromise<V> newProgressivePromise(); <V> Future<V> newSucceededFuture(V result); <V> Future<V> newFailedFuture(Throwable cause);
需要关注的是inEventLoop方法,用于判断当前线程或指定线程是否是EventLoop线程。
EventLoop的概念:http://www.ruanyifeng.com/blog/2013/10/event_loop.html。
另外虽然实现了EventExecutorGroup接口,但EventExecutor并不是容器。
AbstractEventExecutor抽象类:
public abstract class AbstractEventExecutor extends AbstractExecutorService implements EventExecutor {
这个类对一些通用方法做了实现。需要关注的是该类中包含一个私有的内部类EventExecutorIterator(迭代器)
private final class EventExecutorIterator implements Iterator<EventExecutor> { private boolean nextCalled; @Override public boolean hasNext() { return !nextCalled; } @Override public EventExecutor next() { if (!hasNext()) { throw new NoSuchElementException(); } nextCalled = true; return AbstractEventExecutor.this; } @Override public void remove() { throw new UnsupportedOperationException("read-only"); } }
可以看到不管怎么遍历都智能拿到AbstractEventExecutor对象自己。这充分表明AbstractEventExecutor和其子类不是作为EventExecutor容器的。
相关文章推荐
- cdev成员结构体file_operations文件操作结构的分析
- mac 下安装oh my zsh
- 创建Android证书及应用签名说明
- Spring事件驱动
- js文件中引用其他js文件
- [教程]仿photoshop拾色器调整颜色
- Java IO:FileInputStream和FileOutputStream使用详解及源码分析
- Android之Matrix的用法
- openssl/asn1.h file not found的解决方法
- java-eclipse-创建maven项目
- 栈的应用1;后缀表达式求解
- Springmvc精简教程(1)
- js 跨域访问实例
- 一次应用OOM排查
- 站群网站八大盈利模式浅析
- 剑指Offer——不使用循环,判断,选择语句实现1+2+3....+n
- php生成二维码
- stretchableImageWithLeftCapWidth
- 存储之磁盘阵列RAID
- C++ 编译时'setw' was not declared in this scope问题