@Test public void expiration() { int maxTotalWaitTimeMs = 1000; ExponentialTimer timer = new ExponentialTimer(0, 0, 0, maxTotalWaitTimeMs); assertEquals(ExponentialTimer.Result.READY, timer.tick()); CommonUtils.sleepMs(maxTotalWaitTimeMs); assertEquals(ExponentialTimer.Result.EXPIRED, timer.tick()); }
public Result tick() { if (System.currentTimeMillis() >= mLastEventHorizonMs) { return Result.EXPIRED; } if (System.currentTimeMillis() < mNextEventMs) { return Result.NOT_READY; } mNextEventMs = System.currentTimeMillis() + mIntervalMs; long next = Math.min(mIntervalMs * 2, mMaxIntervalMs); if (next < mIntervalMs) { next = Integer.MAX_VALUE; } mIntervalMs = next; mNumEvents++; return Result.READY; }
ExponentialTimer { public Result tick() { if (System.currentTimeMillis() >= mLastEventHorizonMs) { return Result.EXPIRED; } if (System.currentTimeMillis() < mNextEventMs) { return Result.NOT_READY; } mNextEventMs = System.currentTimeMillis() + mIntervalMs; long next = Math.min(mIntervalMs * 2, mMaxIntervalMs); if (next < mIntervalMs) { next = Integer.MAX_VALUE; } mIntervalMs = next; mNumEvents++; return Result.READY; } }
ExponentialTimer { public Result tick() { if (System.currentTimeMillis() >= mLastEventHorizonMs) { return Result.EXPIRED; } if (System.currentTimeMillis() < mNextEventMs) { return Result.NOT_READY; } mNextEventMs = System.currentTimeMillis() + mIntervalMs; long next = Math.min(mIntervalMs * 2, mMaxIntervalMs); if (next < mIntervalMs) { next = Integer.MAX_VALUE; } mIntervalMs = next; mNumEvents++; return Result.READY; } ExponentialTimer(long initialIntervalMs, long maxIntervalMs, long initialWaitTimeMs,
      long maxTotalWaitTimeMs); }
ExponentialTimer { public Result tick() { if (System.currentTimeMillis() >= mLastEventHorizonMs) { return Result.EXPIRED; } if (System.currentTimeMillis() < mNextEventMs) { return Result.NOT_READY; } mNextEventMs = System.currentTimeMillis() + mIntervalMs; long next = Math.min(mIntervalMs * 2, mMaxIntervalMs); if (next < mIntervalMs) { next = Integer.MAX_VALUE; } mIntervalMs = next; mNumEvents++; return Result.READY; } ExponentialTimer(long initialIntervalMs, long maxIntervalMs, long initialWaitTimeMs,
      long maxTotalWaitTimeMs); long getNumEvents(); Result tick(); }
ExponentialTimer { public Result tick() { if (System.currentTimeMillis() >= mLastEventHorizonMs) { return Result.EXPIRED; } if (System.currentTimeMillis() < mNextEventMs) { return Result.NOT_READY; } mNextEventMs = System.currentTimeMillis() + mIntervalMs; long next = Math.min(mIntervalMs * 2, mMaxIntervalMs); if (next < mIntervalMs) { next = Integer.MAX_VALUE; } mIntervalMs = next; mNumEvents++; return Result.READY; } ExponentialTimer(long initialIntervalMs, long maxIntervalMs, long initialWaitTimeMs,
      long maxTotalWaitTimeMs); long getNumEvents(); Result tick();  }