@@ -10,40 +10,39 @@ public final class InfluxDbClientFactory {
10
10
11
11
private static final InfluxDbConfig CONFIG = ProfilingConfig .influxDBConfig ();
12
12
13
- private static final InfluxDbV1Client V1_CLIENT = new InfluxDbV1Client .Builder ()
14
- .host (CONFIG .host ())
15
- .port (CONFIG .port ())
16
- .database (CONFIG .database ())
17
- .username (CONFIG .username ())
18
- .password (CONFIG .password ())
19
- .connectTimeout (CONFIG .connectTimeout ())
20
- .readTimeout (CONFIG .readTimeout ())
21
- .build ();
22
-
23
- private static final InfluxDbV2Client V2_CLIENT = new InfluxDbV2Client .Builder ()
24
- .host (CONFIG .host ())
25
- .port (CONFIG .port ())
26
- .orgName (CONFIG .orgName ())
27
- .database (CONFIG .database ())
28
- .username (CONFIG .username ())
29
- .password (CONFIG .password ())
30
- .connectTimeout (CONFIG .connectTimeout ())
31
- .readTimeout (CONFIG .readTimeout ())
32
- .build ();
33
-
34
- private InfluxDbClientFactory () {
35
- //empty
13
+ private static final InfluxDbClient CLIENT = generateClient ();
14
+
15
+ private static InfluxDbClient generateClient () {
16
+ final String version = CONFIG .version ();
17
+ if (version .startsWith ("2." )) {
18
+ return new InfluxDbV2Client .Builder ()
19
+ .host (CONFIG .host ())
20
+ .port (CONFIG .port ())
21
+ .orgName (CONFIG .orgName ())
22
+ .database (CONFIG .database ())
23
+ .username (CONFIG .username ())
24
+ .password (CONFIG .password ())
25
+ .connectTimeout (CONFIG .connectTimeout ())
26
+ .readTimeout (CONFIG .readTimeout ())
27
+ .build ();
28
+ } else {
29
+ return new InfluxDbV1Client .Builder ()
30
+ .host (CONFIG .host ())
31
+ .port (CONFIG .port ())
32
+ .database (CONFIG .database ())
33
+ .username (CONFIG .username ())
34
+ .password (CONFIG .password ())
35
+ .connectTimeout (CONFIG .connectTimeout ())
36
+ .readTimeout (CONFIG .readTimeout ())
37
+ .build ();
38
+ }
36
39
}
37
40
38
41
public static InfluxDbClient getClient () {
39
- return CONFIG . version (). startsWith ( "2." ) ? getV2Client () : getV1Client () ;
42
+ return CLIENT ;
40
43
}
41
44
42
- public static InfluxDbV1Client getV1Client () {
43
- return V1_CLIENT ;
44
- }
45
-
46
- public static InfluxDbV2Client getV2Client () {
47
- return V2_CLIENT ;
45
+ private InfluxDbClientFactory () {
46
+ //empty
48
47
}
49
48
}
0 commit comments