Skip to content

Commit

Permalink
Connection timeout is now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
prognant committed Apr 1, 2020
1 parent cf5b35c commit b8f7129
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ target/*

# jenv
.java_version
.factorypath
4 changes: 2 additions & 2 deletions src/main/java/org/datadog/jmxfetch/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
@Slf4j
public class Connection {
private static final long CONNECTION_TIMEOUT = 10000;
private static final long JMX_TIMEOUT = 20;
public static final String CLOSED_CLIENT_CAUSE = "The client has been closed";
private static final ThreadFactory daemonThreadFactory = new DaemonThreadFactory();
private JMXConnector connector;
protected MBeanServerConnection mbs;
protected Map<String, Object> env;
protected JMXServiceURL address;
protected long jmx_timeout = 20;

private static <T extends Throwable> T initCause(T wrapper, Throwable wrapped) {
wrapper.initCause(wrapped);
Expand Down Expand Up @@ -108,7 +108,7 @@ public void run() {
});
Object result;
try {
result = mailbox.poll(JMX_TIMEOUT, TimeUnit.SECONDS);
result = mailbox.poll(jmx_timeout, TimeUnit.SECONDS);
if (result == null) {
if (!mailbox.offer("")) {
result = mailbox.take();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/datadog/jmxfetch/RemoteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public RemoteConnection(Map<String, Object> connectionParams) throws IOException
rmiTimeout = DEFAULT_RMI_RESPONSE_TIMEOUT;
}

Integer connectionTimeout;
try {
connectionTimeout = (Integer) connectionParams.get("rmi_connection_timeout");
} catch (final ClassCastException e) {
connectionTimeout =
Integer.parseInt((String) connectionParams.get("rmi_connection_timeout"));
}
if (connectionTimeout != null) {
jmx_timeout = connectionTimeout;
}

user = (String) connectionParams.get("user");
password = (String) connectionParams.get("password");
jmxUrl = (String) connectionParams.get("jmx_url");
Expand Down

0 comments on commit b8f7129

Please sign in to comment.