5
5
6
6
package io .opentelemetry .contrib .jmxscraper .client ;
7
7
8
+ import com .google .errorprone .annotations .CanIgnoreReturnValue ;
8
9
import java .io .IOException ;
9
10
import java .net .MalformedURLException ;
10
11
import java .security .Provider ;
13
14
import java .util .Map ;
14
15
import java .util .logging .Level ;
15
16
import java .util .logging .Logger ;
17
+ import javax .annotation .Nonnull ;
18
+ import javax .annotation .Nullable ;
16
19
import javax .management .remote .JMXConnector ;
17
20
import javax .management .remote .JMXConnectorFactory ;
18
21
import javax .management .remote .JMXServiceURL ;
@@ -29,13 +32,17 @@ public class JmxRemoteClient {
29
32
30
33
private final String host ;
31
34
private final int port ;
35
+ @ Nullable
32
36
private String userName ;
37
+ @ Nullable
33
38
private String password ;
39
+ @ Nullable
34
40
private String profile ;
41
+ @ Nullable
35
42
private String realm ;
36
43
private boolean sslRegistry ;
37
44
38
- private JmxRemoteClient (String host , int port ) {
45
+ private JmxRemoteClient (@ Nonnull String host , int port ) {
39
46
this .host = host ;
40
47
this .port = port ;
41
48
}
@@ -44,23 +51,27 @@ public static JmxRemoteClient createNew(String host, int port) {
44
51
return new JmxRemoteClient (host , port );
45
52
}
46
53
54
+ @ CanIgnoreReturnValue
47
55
public JmxRemoteClient userCredentials (String userName , String password ) {
48
56
this .userName = userName ;
49
57
this .password = password ;
50
58
return this ;
51
59
}
52
60
61
+ @ CanIgnoreReturnValue
53
62
public JmxRemoteClient withRemoteProfile (String profile ) {
54
63
this .profile = profile ;
55
64
return this ;
56
65
}
57
66
67
+ @ CanIgnoreReturnValue
58
68
public JmxRemoteClient withRealm (String realm ) {
59
69
this .realm = realm ;
60
70
return this ;
61
71
}
62
72
63
- public JmxRemoteClient withSSLRegistry () {
73
+ @ CanIgnoreReturnValue
74
+ public JmxRemoteClient withSslRegistry () {
64
75
this .sslRegistry = true ;
65
76
return this ;
66
77
}
@@ -98,23 +109,29 @@ public JMXConnector connect() throws IOException {
98
109
}
99
110
}
100
111
});
101
- } catch (final ReflectiveOperationException e ) {
112
+ } catch (ReflectiveOperationException e ) {
102
113
logger .log (Level .WARNING , "SASL unsupported in current environment: " + e .getMessage (), e );
103
114
}
104
115
105
116
JMXServiceURL url = buildUrl (host , port );
106
117
try {
107
118
if (sslRegistry ) {
108
- return connectSSLRegistry (url , env );
119
+ return doConnectSslRegistry (url , env );
109
120
} else {
110
- return JMXConnectorFactory . connect (url , env );
121
+ return doConnect (url , env );
111
122
}
112
123
} catch (IOException e ) {
113
124
throw new IOException ("Unable to connect to " + url .getHost () + ":" + url .getPort (), e );
114
125
}
115
126
}
116
127
117
- public JMXConnector connectSSLRegistry (JMXServiceURL url , Map <String , Object > env ) {
128
+ @ SuppressWarnings ("BanJNDI" )
129
+ private static JMXConnector doConnect (JMXServiceURL url , Map <String , Object > env )
130
+ throws IOException {
131
+ return JMXConnectorFactory .connect (url , env );
132
+ }
133
+
134
+ public JMXConnector doConnectSslRegistry (JMXServiceURL url , Map <String , Object > env ) {
118
135
throw new IllegalStateException ("TODO" );
119
136
}
120
137
0 commit comments