2828import javax .inject .Inject ;
2929
3030import java .net .URI ;
31- import java .time .Instant ;
3231import java .util .concurrent .Future ;
3332import java .util .concurrent .atomic .AtomicBoolean ;
3433import java .util .concurrent .atomic .AtomicLong ;
@@ -57,7 +56,7 @@ public abstract class RemoteState
5756 private final Duration clusterUnhealthyTimeout ;
5857
5958 private AtomicBoolean isHealthy ;
60- private volatile Instant lastHealthyResponseTime = Instant . now ();
59+ private volatile long lastHealthyResponseTimeNanos = System . nanoTime ();
6160
6261 @ Inject
6362 public RemoteState (HttpClient httpClient , URI remoteUri , RemoteStateConfig remoteStateConfig )
@@ -83,7 +82,7 @@ public synchronized void asyncRefresh()
8382 lastWarningLogged .set (System .nanoTime ());
8483 }
8584
86- if (nanosSince (lastHealthyResponseTime . toEpochMilli ()). toMillis ( ) > clusterUnhealthyTimeout . toMillis () && isHealthy .get ()) {
85+ if (nanosSince (lastHealthyResponseTimeNanos ). compareTo ( clusterUnhealthyTimeout ) > 0 && isHealthy .get ()) {
8786 isHealthy .set (false );
8887 log .warn ("%s:%d marked as unhealthy" , remoteUri .getHost (), remoteUri .getPort ());
8988 }
@@ -115,7 +114,7 @@ public void onSuccess(@Nullable FullJsonResponseHandler.JsonResponse<JsonNode> r
115114 log .debug ("%s:%d was unhealthy, and is now healthy" , remoteUri .getHost (), remoteUri .getPort ());
116115 isHealthy .set (true );
117116 }
118- lastHealthyResponseTime = Instant . now ();
117+ lastHealthyResponseTimeNanos = System . nanoTime ();
119118 }
120119 }
121120 else {
0 commit comments