rename deadUntil to deadUntilNanos

This commit is contained in:
javanna 2016-06-09 16:31:09 +02:00 committed by Luca Cavanna
parent 85606e8a4b
commit c028bf9250
2 changed files with 8 additions and 8 deletions

View File

@ -34,17 +34,17 @@ class DeadHostState {
static final DeadHostState INITIAL_DEAD_STATE = new DeadHostState();
private final int failedAttempts;
private final long deadUntil;
private final long deadUntilNanos;
private DeadHostState() {
this.failedAttempts = 1;
this.deadUntil = System.nanoTime() + MIN_CONNECTION_TIMEOUT_NANOS;
this.deadUntilNanos = System.nanoTime() + MIN_CONNECTION_TIMEOUT_NANOS;
}
DeadHostState(DeadHostState previousDeadHostState) {
long timeoutNanos = (long)Math.min(MIN_CONNECTION_TIMEOUT_NANOS * 2 * Math.pow(2, previousDeadHostState.failedAttempts * 0.5 - 1),
MAX_CONNECTION_TIMEOUT_NANOS);
this.deadUntil = System.nanoTime() + timeoutNanos;
this.deadUntilNanos = System.nanoTime() + timeoutNanos;
this.failedAttempts = previousDeadHostState.failedAttempts + 1;
}
@ -52,15 +52,15 @@ class DeadHostState {
* Returns the timestamp (nanos) till the host is supposed to stay dead without being retried.
* After that the host should be retried.
*/
long getDeadUntil() {
return deadUntil;
long getDeadUntilNanos() {
return deadUntilNanos;
}
@Override
public String toString() {
return "DeadHostState{" +
"failedAttempts=" + failedAttempts +
", deadUntil=" + deadUntil +
", deadUntilNanos=" + deadUntilNanos +
'}';
}
}

View File

@ -224,7 +224,7 @@ public final class RestClient implements Closeable {
private Iterator<HttpHost> nextHost() {
Set<HttpHost> filteredHosts = new HashSet<>(hosts);
for (Map.Entry<HttpHost, DeadHostState> entry : blacklist.entrySet()) {
if (System.nanoTime() - entry.getValue().getDeadUntil() < 0) {
if (System.nanoTime() - entry.getValue().getDeadUntilNanos() < 0) {
filteredHosts.remove(entry.getKey());
}
}
@ -235,7 +235,7 @@ public final class RestClient implements Closeable {
Collections.sort(sortedHosts, new Comparator<Map.Entry<HttpHost, DeadHostState>>() {
@Override
public int compare(Map.Entry<HttpHost, DeadHostState> o1, Map.Entry<HttpHost, DeadHostState> o2) {
return Long.compare(o1.getValue().getDeadUntil(), o2.getValue().getDeadUntil());
return Long.compare(o1.getValue().getDeadUntilNanos(), o2.getValue().getDeadUntilNanos());
}
});
HttpHost deadHost = sortedHosts.get(0).getKey();