package net.glowstone.net;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import net.glowstone.GlowServer;

import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;

public abstract class GlowSocketServer extends GlowNetworkServer {
    protected final EventLoopGroup bossGroup;
    protected final EventLoopGroup workerGroup;
    protected final ServerBootstrap bootstrap;

    public GlowSocketServer(GlowServer server, CountDownLatch latch) {
        super(server, latch);
        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
        workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
        bootstrap = new ServerBootstrap();

        bootstrap.group(bossGroup, workerGroup)
                .channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
                .childOption(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.SO_KEEPALIVE, true);
    }

    public ChannelFuture bind(InetSocketAddress address) {
        return this.bootstrap.bind(address).addListener(future -> {
            if (future.isSuccess()) {
                onBindSuccess(address);
            } else {
                onBindFailure(address, future.cause());
            }
        });
    }

    public void shutdown() {
        bootstrap.childGroup().shutdownGracefully();
        bootstrap.group().shutdownGracefully();
    }
}

@@ -64,16 +64,49 @@
 tstrap;%0A
+import io.netty.channel.Channel;%0A
 import i
@@ -786,16 +786,112 @@
 otstrap;
+%0A    protected Channel channel;%0A%0A    public Channel getChannel() %7B%0A        return channel;%0A    %7D
 %0A%0A    pu
@@ -1579,22 +1579,39 @@
         
-return
+ChannelFuture cfuture =
  this.bo
@@ -1837,16 +1837,77 @@
     %7D);%0A
+        channel = cfuture.channel();%0A        return cfuture;%0A
     %7D%0A%0A 
@@ -1930,24 +1930,49 @@
 hutdown() %7B%0A
+        channel.close();%0A
         boot

Store serverbootstrapchannel (#419)