Java Code Examples for io.netty.channel.Channel#closeFuture()

The following examples show how to use io.netty.channel.Channel#closeFuture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyIoAcceptor.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void unbind(SocketAddress address) {
  Channel channel = boundAddresses.get(address);
  if (channel != null) {
    ChannelFuture fut;
    if (channel.isOpen()) {
      fut = channel.close();
    } else {
      fut = channel.closeFuture();
    }
    try {
      fut.sync();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
}
 
Example 2
Source File: NettyIoAcceptor.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Override
public void unbind(SocketAddress address) {
    Channel channel = boundAddresses.get(address);
    if (channel != null) {
        ChannelFuture fut;
        if (channel.isOpen()) {
            fut = channel.close();
        } else {
            fut = channel.closeFuture();
        }
        try {
            fut.sync();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
 
Example 3
Source File: ApiServer.java    From netty.book.kor with MIT License 6 votes vote down vote up
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(bossThreadCount);
    EventLoopGroup workerGroup = new NioEventLoopGroup(workerThreadCount);
    ChannelFuture channelFuture = null;

    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ApiServerInitializer(null));

        Channel ch = b.bind(8080).sync().channel();

        channelFuture = ch.closeFuture();
        channelFuture.sync();
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    }
    finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example 4
Source File: NettyIoAcceptor.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void unbind(SocketAddress address) {
  Channel channel = boundAddresses.get(address);
  if (channel != null) {
    ChannelFuture fut;
    if (channel.isOpen()) {
      fut = channel.close();
    } else {
      fut = channel.closeFuture();
    }
    try {
      fut.sync();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
}
 
Example 5
Source File: StreamListener.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private void close() {
    if (closed) {
        // do nothing
        return;
    }
    closed = true;
    for (Channel channel : partitionMap.keySet()) {
        channel.closeFuture(); // don't wait synchronously, no need
    }
    Exception lastException = null;
    synchronized (closeables) {
        for (AutoCloseable c : closeables) {
            try {
                c.close();
            } catch (Exception e) {
                LOG.error("Unexpected exception", e);
                lastException = e;
            }
        }
    }
    if (lastException != null) {
        throw new RuntimeException(lastException);
    }
}
 
Example 6
Source File: EchoServerWithFuture.java    From netty.book.kor with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new EchoServerHandlerWithFuture());
            }
        });

        ChannelFuture bindFuture = b.bind(8888);
        System.out.println("Bind 시작.");
        bindFuture.sync();
        System.out.println("Bind 완료.");

        Channel serverChannel = bindFuture.channel();
        ChannelFuture closeFuture = serverChannel.closeFuture();
        closeFuture.sync();
    }
    finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}