@Test public void startsIdle() { KeepAliveEnforcer enforcer = new KeepAliveEnforcer(false, 0, TimeUnit.NANOSECONDS, ticker); for (int i = 0; i < KeepAliveEnforcer.MAX_PING_STRIKES; i++) { assertThat(enforcer.pingAcceptable()).isTrue(); } assertThat(enforcer.pingAcceptable()).isFalse(); }
@CheckReturnValue public boolean pingAcceptable() { long now = ticker.nanoTime(); boolean valid; if (!hasOutstandingCalls && !permitWithoutCalls) { valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0; } else { valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0; } if (!valid) { pingStrikes++; return !(pingStrikes > MAX_PING_STRIKES); } else { lastValidPingTime = now; return true; } }
KeepAliveEnforcer { @CheckReturnValue public boolean pingAcceptable() { long now = ticker.nanoTime(); boolean valid; if (!hasOutstandingCalls && !permitWithoutCalls) { valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0; } else { valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0; } if (!valid) { pingStrikes++; return !(pingStrikes > MAX_PING_STRIKES); } else { lastValidPingTime = now; return true; } } }
KeepAliveEnforcer { @CheckReturnValue public boolean pingAcceptable() { long now = ticker.nanoTime(); boolean valid; if (!hasOutstandingCalls && !permitWithoutCalls) { valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0; } else { valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0; } if (!valid) { pingStrikes++; return !(pingStrikes > MAX_PING_STRIKES); } else { lastValidPingTime = now; return true; } } KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit); @VisibleForTesting  KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit, Ticker ticker); }
KeepAliveEnforcer { @CheckReturnValue public boolean pingAcceptable() { long now = ticker.nanoTime(); boolean valid; if (!hasOutstandingCalls && !permitWithoutCalls) { valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0; } else { valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0; } if (!valid) { pingStrikes++; return !(pingStrikes > MAX_PING_STRIKES); } else { lastValidPingTime = now; return true; } } KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit); @VisibleForTesting  KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit, Ticker ticker); @CheckReturnValue boolean pingAcceptable(); void resetCounters(); void onTransportActive(); void onTransportIdle(); }
KeepAliveEnforcer { @CheckReturnValue public boolean pingAcceptable() { long now = ticker.nanoTime(); boolean valid; if (!hasOutstandingCalls && !permitWithoutCalls) { valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0; } else { valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0; } if (!valid) { pingStrikes++; return !(pingStrikes > MAX_PING_STRIKES); } else { lastValidPingTime = now; return true; } } KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit); @VisibleForTesting  KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, TimeUnit unit, Ticker ticker); @CheckReturnValue boolean pingAcceptable(); void resetCounters(); void onTransportActive(); void onTransportIdle();  }