Example usage for io.netty.channel ChannelHandlerContext executor

List of usage examples for io.netty.channel ChannelHandlerContext executor

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext executor.

Prototype

EventExecutor executor();

Source Link

Document

Returns the EventExecutor which is used to execute an arbitrary task.

Usage

From source file:tp.MyJZLibEncoder.java

@Override
public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
    ChannelFuture f = finishEncode(ctx, ctx.newPromise());
    f.addListener(new ChannelFutureListener() {
        @Override//from  w w w  .  j av  a 2s .c o m
        public void operationComplete(ChannelFuture f) throws Exception {
            ctx.close(promise);
        }
    });

    if (!f.isDone()) {
        // Ensure the channel is closed even if the write operation completes in time.
        ctx.executor().schedule(new Runnable() {
            @Override
            public void run() {
                ctx.close(promise);
            }
        }, 10, TimeUnit.SECONDS); // FIXME: Magic number
    }
}