Netty源码解读Promise

Promise是future下面一个独特的类,可以对future进行标记

package netty.test;

/**
 * @Author:chaoqiang.zhou
 * @Description:
 * @Date:Create in 15:10 2017/10/19
 */

import io.netty.util.concurrent.GenericFutureListener;

/**
 * Future中的一个特别的可写入的获取结果
 */
public interface Promise<V> extends io.netty.util.concurrent.Future<V> {

    /**
     * Marks this future as a success and notifies all
     * listeners.
     * <p>
     * If it is success or failed already it will throw an {@link IllegalStateException}.
     */
    /**
     * 标记future为成功,并且通知所有的listener
     * 如果已经是成功或者异常的话,会抛出IllegalStateException
     * @param result
     * @return
     */
    Promise<V> setSuccess(V result);

    /**
     * Marks this future as a success and notifies all
     * listeners.
     *
     * @return {@code true} if and only if successfully marked this future as
     * a success. Otherwise {@code false} because this future is
     * already marked as either a success or a failure.
     */
    /**
     * 标记future为成功,并且通知所有的listener
     * 如果已经是成功或者异常的话,会抛出IllegalStateException
     * 仅仅当成功的标记为true时,才返回true,否则的话,就返回false
     * @param result
     * @return
     */
    boolean trySuccess(V result);


    /**
     * 与标记成功类似
     * @param cause
     * @return
     */
    Promise<V> setFailure(Throwable cause);


    boolean tryFailure(Throwable cause);

    /**
     * Make this future impossible to cancel.
     *
     * @return {@code true} if and only if successfully marked this future as uncancellable or it is already done
     * without being cancelled.  {@code false} if this future has been cancelled already.
     */
    /**
     * 标记该future为不可以被cancle
     * 只有当标记成功,或者之前已经被标记过后才返回true
     * @return
     */
    boolean setUncancellable();

    @Override
    Promise<V> addListener(GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener);

    @Override
    Promise<V> addListeners(GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners);

    @Override
    Promise<V> removeListener(GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener);

    @Override
    Promise<V> removeListeners(GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners);

    @Override
    Promise<V> await() throws InterruptedException;

    @Override
    Promise<V> awaitUninterruptibly();

    @Override
    Promise<V> sync() throws InterruptedException;

    @Override
    Promise<V> syncUninterruptibly();
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值