class MySQLNegotiateHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
        if (msg instanceof MySQLHandshakePacket) {
            MySQLHandshakePacket handshake = (MySQLHandshakePacket) msg;
            MySQLHandshakeResponse41Packet handshakeResponsePacket = new MySQLHandshakeResponse41Packet(1, MAX_PACKET_SIZE, CHARACTER_SET, username);
            handshakeResponsePacket.setAuthResponse(generateAuthResponse(handshake.getAuthPluginData().getAuthPluginData()));
            handshakeResponsePacket.setCapabilityFlags(generateClientCapability());
            handshakeResponsePacket.setDatabase("mysql");
            handshakeResponsePacket.setAuthPluginName(MySQLAuthenticationMethod.SECURE_PASSWORD_AUTHENTICATION);
            ctx.channel().writeAndFlush(handshakeResponsePacket);
            serverInfo = new ServerInfo();
            serverInfo.setServerVersion(new ServerVersion(handshake.getServerVersion()));
            return;
        }
        if (msg instanceof MySQLOKPacket) {
            ctx.channel().pipeline().remove(this);
            authResultCallback.setSuccess(serverInfo);
            return;
        }
        MySQLErrPacket error = (MySQLErrPacket) msg;
        ctx.channel().close();
        throw new RuntimeException(error.getErrorMessage());
    }

}