美文网首页
Netty:NioEventLoopGroup 之EventEx

Netty:NioEventLoopGroup 之EventEx

作者: zh_harry | 来源:发表于2019-07-05 13:23 被阅读0次
image
package io.netty.util.concurrent;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 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.

EventExecutorGroup该接口对EventExecutornext方法负责,除此之外,还负责处理它的生命周期,并允许在全局范围内关闭它们。

public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor> {

    /**
     * Returns {@code true} if and only if all {@link EventExecutor}s managed by this {@link EventExecutorGroup}
     * are being {@linkplain #shutdownGracefully() shut down gracefully} or was {@linkplain #isShutdown() shut down}.
     */
    boolean isShuttingDown();

当且仅当被EventExecutorGroup管理的EventExecutor全闭被优雅的关闭,或者isShutdowntrue

    /**
     * Shortcut method for {@link #shutdownGracefully(long, long, TimeUnit)} with sensible default values.
     *
     * @return the {@link #terminationFuture()}
     */
    Future<?> shutdownGracefully();

shutdownGracefully(long, long, TimeUnit)方法的快捷方式,该方法使用合适的默认值。

    /**
     * Signals this executor that the caller wants the executor to be shut down.  Once this method is called,

     * {@link #isShuttingDown()} starts to return {@code true}, and the executor prepares to shut itself down.
     * Unlike {@link #shutdown()}, graceful shutdown ensures that no tasks are submitted for <i>'the quiet period'</i>
     * (usually a couple seconds) before it shuts itself down.  If a task is submitted during the quiet period,
     * it is guaranteed to be accepted and the quiet period will start over.

一旦该方法被调用,表明executor的调用者希望它被shutdownisShuttingDown此时已经开始返回true,executor准备shutdown自己。
shutdown方法不同,优雅shutdown要确保在quiet peroid (静默周期)内不会有新的任务被提交。(换句话说,如果有任务提交,则不能关闭)
在它shutdown之前,通常为几秒。如果有 task在(静默周期)内被提交,它将被接受,而且静默周期会重新开始。

     * @param quietPeriod the quiet period as described in the documentation 
静默周期
     * @param timeout     the maximum amount of time to wait until the executor is {@linkplain #shutdown()}
     *                    regardless if a task was submitted during the quiet period 
超时时间  如果超时,不管有没有任务提交都会关闭
     * @param unit        the unit of {@code quietPeriod} and {@code timeout}  
静默周期和超时时间的单位 
     *
     * @return the {@link #terminationFuture()}
     */
    Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit);
    /**
     * Returns the {@link Future} which is notified when all {@link EventExecutor}s managed by this
     * {@link EventExecutorGroup} have been terminated.
     */
    Future<?> terminationFuture();

当所有的EventExecutor中止的时侯将返回Future

以下方法为过期方法


    /**
     * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead.
     */
    @Override
    @Deprecated
    void shutdown();

    /**
     * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead.
     */
    @Override
    @Deprecated
    List<Runnable> shutdownNow();
    /**
     * Returns one of the {@link EventExecutor}s managed by this {@link EventExecutorGroup}.
     */
    EventExecutor next();

返回下一个EventExecutor

以下方法为父接口重写方法


    @Override
    Iterator<EventExecutor> iterator();

    @Override
    Future<?> submit(Runnable task);

    @Override
    <T> Future<T> submit(Runnable task, T result);

    @Override
    <T> Future<T> submit(Callable<T> task);

    @Override
    ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);

    @Override
    <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit);

    @Override
    ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);

    @Override
    ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);
}

相关文章

网友评论

      本文标题:Netty:NioEventLoopGroup 之EventEx

      本文链接:https://www.haomeiwen.com/subject/ozishctx.html