NioEventLoop类


NioEventLoop继承关系图

Future

  netty包的Future继承了JDK里的Future,主要是增加了addListener()removeListener()方法。

public interface Future extends java.util.concurrent.Future {

    boolean isSuccess();

    boolean isCancellable();

    Throwable cause();

    Future addListener(GenericFutureListener> listener);

    Future addListeners(GenericFutureListener>... listeners);

    Future removeListener(GenericFutureListener> listener);

    Future removeListeners(GenericFutureListener>... listeners);

    Future sync() throws InterruptedException;

    Future syncUninterruptibly();

    Future await() throws InterruptedException;

    Future awaitUninterruptibly();

    boolean await(long timeout, TimeUnit unit) throws InterruptedException;

    boolean await(long timeoutMillis) throws InterruptedException;

    boolean awaitUninterruptibly(long timeout, TimeUnit unit);

    boolean awaitUninterruptibly(long timeoutMillis);

    V getNow();

    @Override
    boolean cancel(boolean mayInterruptIfRunning);
}

Promise

  Promise是一个可写的Future

public interface Promise extends Future {

    Promise setSuccess(V result);

    boolean trySuccess(V result);

    Promise setFailure(Throwable cause);

    boolean tryFailure(Throwable cause);

    boolean setUncancellable();

    @Override
    Promise addListener(GenericFutureListener> listener);

    @Override
    Promise addListeners(GenericFutureListener>... listeners);

    @Override
    Promise removeListener(GenericFutureListener> listener);

    @Override
    Promise removeListeners(GenericFutureListener>... listeners);

    @Override
    Promise await() throws InterruptedException;

    @Override
    Promise awaitUninterruptibly();

    @Override
    Promise sync() throws InterruptedException;

    @Override
    Promise syncUninterruptibly();
}

EventExecutor

  EventExecutor主要是提供了inEventLoop()方法查看一个线程是否在event loop中执行。

public interface EventExecutor extends EventExecutorGroup {
    //返回this
    @Override
    EventExecutor next();
    
    EventExecutorGroup parent();

    boolean inEventLoop();

    boolean inEventLoop(Thread thread);

     Promise newPromise();

     ProgressivePromise newProgressivePromise();
    //这里的Future是netty包里面的,而不是jdk里面的那个
     Future newSucceededFuture(V result);

     Future newFailedFuture(Throwable cause);
}

AbstractEventExecutor

  AbstractEventExecutor没有实现具体的逻辑,主要是将实现代理给父类,或者抛出UnsupportedOperationException异常。

AbstractScheduledEventExecutor

  AbstractScheduledEventExecutor实现了schedule()方法,具体实现是将RunnableCallable封装成ScheduledFutureTask,然后加到字段PriorityQueue>队列中。
  队列中的ScheduledFutureTask是按照剩余时间大小排列的,AbstractEventExecutor还提供了pollScheduledTask()获取下一个到时的任务。

OrderedEventExecutor

  OrderedEventExecutor只是一个标记接口,没有任何方法,表示任务会按照顺序执行。

EventLoop

  EventLoop只是将父类parent()方法返回,从EventExecutorGroup,改为EventLoopGroup

public interface EventLoop extends OrderedEventExecutor, EventLoopGroup {
    @Override
    EventLoopGroup parent();
}

SingleThreadEventExecutor

你可能感兴趣的:(NioEventLoop类)