1
1
package org .datadog .jmxfetch ;
2
2
3
3
import lombok .extern .slf4j .Slf4j ;
4
+ import org .datadog .jmxfetch .util .JmxfetchRmiClientSocketFactory ;
4
5
5
6
import java .io .IOException ;
6
7
import java .net .MalformedURLException ;
@@ -20,13 +21,15 @@ public class RemoteConnection extends Connection {
20
21
private String password ;
21
22
private String path = "jmxrmi" ;
22
23
private String jmxUrl ;
23
- private String rmiTimeout ;
24
+ private Integer rmiTimeout ;
25
+ private Integer rmiConnectionTimeout ;
24
26
private static final String TRUST_STORE_PATH_KEY = "trust_store_path" ;
25
27
private static final String TRUST_STORE_PASSWORD_KEY = "trust_store_password" ;
26
28
private static final String KEY_STORE_PATH_KEY = "key_store_path" ;
27
29
private static final String KEY_STORE_PASSWORD_KEY = "key_store_password" ;
28
- private static final String DEFAULT_RMI_RESPONSE_TIMEOUT =
29
- "15000" ; // Match the collection period default
30
+ private static final int DEFAULT_RMI_CONNECTION_TIMEOUT = 20000 ;
31
+ private static final int DEFAULT_RMI_TIMEOUT =
32
+ 15000 ; // Match the collection period default
30
33
31
34
/** RemoteConnection constructor for specified remote connection parameters. */
32
35
public RemoteConnection (Map <String , Object > connectionParams ) throws IOException {
@@ -38,24 +41,22 @@ public RemoteConnection(Map<String, Object> connectionParams) throws IOException
38
41
}
39
42
40
43
try {
41
- rmiTimeout = (String ) connectionParams .get ("rmi_client_timeout" );
42
- } catch (ClassCastException e ) {
43
- rmiTimeout = Integer .toString (( Integer ) connectionParams .get ("rmi_client_timeout" ));
44
+ rmiTimeout = (Integer ) connectionParams .get ("rmi_client_timeout" );
45
+ } catch (final ClassCastException e ) {
46
+ rmiTimeout = Integer .parseInt (( String ) connectionParams .get ("rmi_client_timeout" ));
44
47
}
45
-
46
48
if (rmiTimeout == null ) {
47
- rmiTimeout = DEFAULT_RMI_RESPONSE_TIMEOUT ;
49
+ rmiTimeout = DEFAULT_RMI_TIMEOUT ;
48
50
}
49
51
50
- Integer connectionTimeout ;
51
52
try {
52
- connectionTimeout = (Integer ) connectionParams .get ("rmi_connection_timeout" );
53
+ rmiConnectionTimeout = (Integer ) connectionParams .get ("rmi_connection_timeout" );
53
54
} catch (final ClassCastException e ) {
54
- connectionTimeout =
55
+ rmiConnectionTimeout =
55
56
Integer .parseInt ((String ) connectionParams .get ("rmi_connection_timeout" ));
56
57
}
57
- if (connectionTimeout ! = null ) {
58
- jmxTimeout = connectionTimeout ;
58
+ if (rmiConnectionTimeout = = null ) {
59
+ rmiConnectionTimeout = DEFAULT_RMI_CONNECTION_TIMEOUT ;
59
60
}
60
61
61
62
user = (String ) connectionParams .get ("user" );
@@ -65,6 +66,7 @@ public RemoteConnection(Map<String, Object> connectionParams) throws IOException
65
66
if (connectionParams .containsKey ("path" )) {
66
67
path = (String ) connectionParams .get ("path" );
67
68
}
69
+
68
70
env = getEnv (connectionParams );
69
71
address = getAddress ();
70
72
@@ -96,25 +98,18 @@ public RemoteConnection(Map<String, Object> connectionParams) throws IOException
96
98
log .info ("Setting keyStore path: " + keyStorePath + " and keyStorePassword" );
97
99
}
98
100
}
99
-
100
- // Set an RMI timeout so we don't get stuck waiting for a bean to report a value
101
- System .setProperty ("sun.rmi.transport.tcp.responseTimeout" , rmiTimeout );
102
-
103
101
createConnection ();
104
102
}
105
103
106
104
private Map <String , Object > getEnv (Map <String , Object > connectionParams ) {
107
-
108
105
Map <String , Object > environment = new HashMap <String , Object >();
109
-
110
- if (connectionParams .containsKey ("rmi_registry_ssl" )
111
- && (Boolean ) connectionParams .get ("rmi_registry_ssl" )) {
112
- SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory ();
113
- environment .put ("com.sun.jndi.rmi.factory.socket" , csf );
114
- environment .put (RMIConnectorServer .RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE , csf );
115
- }
116
-
117
- environment .put (JMXConnector .CREDENTIALS , new String [] {user , password });
106
+ boolean useSsl = (connectionParams .containsKey ("rmi_registry_ssl" )
107
+ && (Boolean ) connectionParams .get ("rmi_registry_ssl" ));
108
+ JmxfetchRmiClientSocketFactory csf =
109
+ new JmxfetchRmiClientSocketFactory (rmiTimeout , rmiConnectionTimeout , useSsl );
110
+ environment .put ("com.sun.jndi.rmi.factory.socket" , csf );
111
+ environment .put (RMIConnectorServer .RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE , csf );
112
+ environment .put (JMXConnector .CREDENTIALS , new String [] { user , password });
118
113
return environment ;
119
114
}
120
115
0 commit comments