in server-common/src/main/java/org/apache/cassandra/sidecar/common/server/JmxClient.java [164:207]
protected void connect()
{
int attempts = 1;
int maxAttempts = connectionMaxRetries;
Throwable lastThrown = null;
while (attempts <= maxAttempts)
{
try
{
connectInternal(attempts);
return;
}
// Unrecoverable errors
catch (SecurityException securityException)
{
// If we can't connect because we have bad credentials, don't retry
connected = false;
String errorMessage = securityException.getMessage() != null
? securityException.getMessage()
: "JMX Authentication failed";
throw new JmxAuthenticationException(errorMessage, securityException);
}
catch (RuntimeException runtimeException)
{
// catch exceptions coming from the lambdas and wrap them in a JmxAuthenticationException
throw new JmxAuthenticationException(runtimeException);
}
// Anything else is recoverable so we should retry.
catch (Throwable t)
{
lastThrown = t;
if (attempts < maxAttempts)
{
LOGGER.info("Could not connect to JMX on {} after {} attempts. Will retry.",
jmxServiceURL, attempts, t);
Uninterruptibles.sleepUninterruptibly(connectionRetryDelay.quantity(), connectionRetryDelay.unit());
}
attempts++;
}
}
String error = "Failed to connect to JMX, which was unreachable after " + attempts + " attempts.";
LOGGER.error(error, lastThrown);
throw new RuntimeException(error, lastThrown);
}