public void run() throws Exception {
final EventLoopGroup bossGroup = new NioEventLoopGroup(settings.threadPoolBoss);
final EventLoopGroup workerGroup = new NioEventLoopGroup(settings.threadPoolWorker);
final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("gremlin-%d").build();
final EventExecutorGroup gremlinGroup = new DefaultEventExecutorGroup(settings.gremlinPool, threadFactory);
try {
final ServerBootstrap b = new ServerBootstrap();
// when high value is reached then the channel becomes non-writeable and stays like that until the
// low value is so that there is time to recover
b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, settings.writeBufferLowWaterMark);
b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, settings.writeBufferHighWaterMark);
b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
final GremlinExecutor gremlinExecutor = initializeGremlinExecutor(gremlinGroup, workerGroup);
final Channelizer channelizer = createChannelizer(settings);
channelizer.init(settings, gremlinExecutor, gremlinGroup, graphs.get(), workerGroup);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(channelizer);
ch = b.bind(settings.host, settings.port).sync().channel();
logger.info("Gremlin Server configured with worker thread pool of {} and boss thread pool of {}",
settings.threadPoolWorker, settings.threadPoolBoss);
logger.info("Channel started at port {}.", settings.port);
serverReady.ifPresent(future -> future.complete(null));
ch.closeFuture().sync();
} finally {
logger.info("Shutting down thread pools");
gremlinGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
logger.info("Gremlin Server - shutdown complete");
}