55
66package io .opentelemetry .contrib .jmxscraper .client ;
77
8+ import com .google .errorprone .annotations .CanIgnoreReturnValue ;
89import java .io .IOException ;
910import java .net .MalformedURLException ;
1011import java .security .Provider ;
1314import java .util .Map ;
1415import java .util .logging .Level ;
1516import java .util .logging .Logger ;
17+ import javax .annotation .Nonnull ;
18+ import javax .annotation .Nullable ;
1619import javax .management .remote .JMXConnector ;
1720import javax .management .remote .JMXConnectorFactory ;
1821import javax .management .remote .JMXServiceURL ;
@@ -29,13 +32,17 @@ public class JmxRemoteClient {
2932
3033 private final String host ;
3134 private final int port ;
35+ @ Nullable
3236 private String userName ;
37+ @ Nullable
3338 private String password ;
39+ @ Nullable
3440 private String profile ;
41+ @ Nullable
3542 private String realm ;
3643 private boolean sslRegistry ;
3744
38- private JmxRemoteClient (String host , int port ) {
45+ private JmxRemoteClient (@ Nonnull String host , int port ) {
3946 this .host = host ;
4047 this .port = port ;
4148 }
@@ -44,23 +51,27 @@ public static JmxRemoteClient createNew(String host, int port) {
4451 return new JmxRemoteClient (host , port );
4552 }
4653
54+ @ CanIgnoreReturnValue
4755 public JmxRemoteClient userCredentials (String userName , String password ) {
4856 this .userName = userName ;
4957 this .password = password ;
5058 return this ;
5159 }
5260
61+ @ CanIgnoreReturnValue
5362 public JmxRemoteClient withRemoteProfile (String profile ) {
5463 this .profile = profile ;
5564 return this ;
5665 }
5766
67+ @ CanIgnoreReturnValue
5868 public JmxRemoteClient withRealm (String realm ) {
5969 this .realm = realm ;
6070 return this ;
6171 }
6272
63- public JmxRemoteClient withSSLRegistry () {
73+ @ CanIgnoreReturnValue
74+ public JmxRemoteClient withSslRegistry () {
6475 this .sslRegistry = true ;
6576 return this ;
6677 }
@@ -98,23 +109,29 @@ public JMXConnector connect() throws IOException {
98109 }
99110 }
100111 });
101- } catch (final ReflectiveOperationException e ) {
112+ } catch (ReflectiveOperationException e ) {
102113 logger .log (Level .WARNING , "SASL unsupported in current environment: " + e .getMessage (), e );
103114 }
104115
105116 JMXServiceURL url = buildUrl (host , port );
106117 try {
107118 if (sslRegistry ) {
108- return connectSSLRegistry (url , env );
119+ return doConnectSslRegistry (url , env );
109120 } else {
110- return JMXConnectorFactory . connect (url , env );
121+ return doConnect (url , env );
111122 }
112123 } catch (IOException e ) {
113124 throw new IOException ("Unable to connect to " + url .getHost () + ":" + url .getPort (), e );
114125 }
115126 }
116127
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 ) {
118135 throw new IllegalStateException ("TODO" );
119136 }
120137
0 commit comments