Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Make pauseBeforeReconnect overridable #41
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryShea committed Nov 22, 2018
1 parent 179e335 commit 3a4980b
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -120,13 +120,17 @@ default SocketChannel openSocketChannel(@NotNull InetSocketAddress socketAddress
return sc;
Thread.yield();
// If nothing is listening, socketChannel returns pretty much immediately so we support a pause here
long pauseMillis = (startMs + pauseMillisBeforeReconnect()) - System.currentTimeMillis();
if (Jvm.isDebugEnabled(this.getClass()))
Jvm.debug().on(this.getClass(), "Waiting for reconnect "+pauseMillis+" ms");
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(pauseMillis));
pauseBeforeReconnect(startMs);
}
}

default void pauseBeforeReconnect(long startMs) {
long pauseMillis = (startMs + pauseMillisBeforeReconnect()) - System.currentTimeMillis();
if (Jvm.isDebugEnabled(this.getClass()))
Jvm.debug().on(this.getClass(), "Waiting for reconnect "+pauseMillis+" ms");
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(pauseMillis));
}

/**
* allows control of a backoff strategy
*
Expand Down

0 comments on commit 3a4980b

Please sign in to comment.