//sleep 100 to prevent thrashing and facilitate interruption
public boolean connect(long timeoutMs) {
        if (LOG.isDebugEnabled()) LOG.debug("Connecting to JMX URL: {} ({})", url, ((timeoutMs == -1) ? "indefinitely" : timeoutMs+"ms timeout"));
        long startMs = System.currentTimeMillis();
        long endMs = (timeoutMs == -1) ? Long.MAX_VALUE : (startMs + timeoutMs);
        long currentTime = startMs;
        Throwable lastError = null;
        int attempt = 0;
        while (currentTime <= endMs) {
            currentTime = System.currentTimeMillis();
            if (attempt != 0) sleep(100); //sleep 100 to prevent thrashing and facilitate interruption
            if (LOG.isTraceEnabled()) LOG.trace("trying connection to {} at time {}", url, currentTime);
            try {
                connect();
                return true;
            } catch (Exception e) {
                Exceptions.propagateIfFatal(e);
                if (!terminated.get() && shouldRetryOn(e)) {
                    if (LOG.isDebugEnabled()) LOG.debug("Attempt {} failed connecting to {} ({})", new Object[] {attempt + 1, url, e.getMessage()});
                    lastError = e;
                } else {
                    throw Exceptions.propagate(e);
                }
            }
            attempt++;
        }
        LOG.warn("unable to connect to JMX url: "+url, lastError);
        return false;
    }
while (currentTime <= endMs) {
currentTime = System.currentTimeMillis();
if (attempt != 0) sleep(100); //sleep 100 to prevent thrashing and facilitate interruption
if (LOG.isTraceEnabled()) LOG.trace("trying connection to {} at time {}", url, currentTime);
try {
public boolean connect(long timeoutMs) {
if (LOG.isDebugEnabled()) LOG.debug("Connecting to JMX URL: {} ({})", url, ((timeoutMs == -1) ? "indefinitely" : timeoutMs+"ms timeout"));
long startMs = System.currentTimeMillis();
long endMs = (timeoutMs == -1) ? Long.MAX_VALUE : (startMs + timeoutMs);
long currentTime = startMs;
Throwable lastError = null;
int attempt = 0;
while (currentTime <= endMs) {
currentTime = System.currentTimeMillis();
if (attempt != 0) sleep(100); //sleep 100 to prevent thrashing and facilitate interruption
if (LOG.isTraceEnabled()) LOG.trace("trying connection to {} at time {}", url, currentTime);
try {
connect();
return true;
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
if (!terminated.get() && shouldRetryOn(e)) {
if (LOG.isDebugEnabled()) LOG.debug("Attempt {} failed connecting to {} ({})", new Object[] {attempt + 1, url, e.getMessage()});
lastError = e;
} else {
public boolean connect(long timeoutMs) {
if (LOG.isDebugEnabled()) LOG.debug("Connecting to JMX URL: {} ({})", url, ((timeoutMs == -1) ? "indefinitely" : timeoutMs+"ms timeout"));
long startMs = System.currentTimeMillis();
long endMs = (timeoutMs == -1) ? Long.MAX_VALUE : (startMs + timeoutMs);
long currentTime = startMs;
Throwable lastError = null;
int attempt = 0;
while (currentTime <= endMs) {
currentTime = System.currentTimeMillis();
if (attempt != 0) sleep(100); //sleep 100 to prevent thrashing and facilitate interruption
if (LOG.isTraceEnabled()) LOG.trace("trying connection to {} at time {}", url, currentTime);
try {
connect();
return true;
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
if (!terminated.get() && shouldRetryOn(e)) {
if (LOG.isDebugEnabled()) LOG.debug("Attempt {} failed connecting to {} ({})", new Object[] {attempt + 1, url, e.getMessage()});
lastError = e;
} else {
throw Exceptions.propagate(e);
}
}
attempt++;
}
LOG.warn("unable to connect to JMX url: "+url, lastError);
return false;
}