public void start(final ApplicationContext applicationContext) throws Exception {
NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
try {
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ServerHandlerImpl());
ch.pipeline().addLast(new SomeOtherHandler());
}
@Override
protected void channelActive(ChannelHandlerContext ctx) throws Exception {
Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new CredentialsClientHandler());
}
});
clientBootstrap.group(ctx.channel().eventLoop());
ChannelFuture future = clientBootstrap.connect(host, port);
}
});