@Test public void timeout() { final long timeoutMs = 500; final long slackMs = 200; TimeoutRefresh timeoutRefresh = new TimeoutRefresh(timeoutMs); assertTrue(timeoutRefresh.attempt()); assertFalse(timeoutRefresh.attempt()); CommonUtils.sleepMs(timeoutMs); CommonUtils.sleepMs(slackMs); assertTrue(timeoutRefresh.attempt()); assertFalse(timeoutRefresh.attempt()); }
@Override public boolean attempt() { if (mFirstAttempt || (CommonUtils.getCurrentMs() - mLastAttempTimeMs) > mRefreshPeriodMs) { mLastAttempTimeMs = CommonUtils.getCurrentMs(); mFirstAttempt = false; return true; } return false; }
TimeoutRefresh implements RefreshPolicy { @Override public boolean attempt() { if (mFirstAttempt || (CommonUtils.getCurrentMs() - mLastAttempTimeMs) > mRefreshPeriodMs) { mLastAttempTimeMs = CommonUtils.getCurrentMs(); mFirstAttempt = false; return true; } return false; } }
TimeoutRefresh implements RefreshPolicy { @Override public boolean attempt() { if (mFirstAttempt || (CommonUtils.getCurrentMs() - mLastAttempTimeMs) > mRefreshPeriodMs) { mLastAttempTimeMs = CommonUtils.getCurrentMs(); mFirstAttempt = false; return true; } return false; } TimeoutRefresh(long refreshPeriodMs); }
TimeoutRefresh implements RefreshPolicy { @Override public boolean attempt() { if (mFirstAttempt || (CommonUtils.getCurrentMs() - mLastAttempTimeMs) > mRefreshPeriodMs) { mLastAttempTimeMs = CommonUtils.getCurrentMs(); mFirstAttempt = false; return true; } return false; } TimeoutRefresh(long refreshPeriodMs); @Override boolean attempt(); }
TimeoutRefresh implements RefreshPolicy { @Override public boolean attempt() { if (mFirstAttempt || (CommonUtils.getCurrentMs() - mLastAttempTimeMs) > mRefreshPeriodMs) { mLastAttempTimeMs = CommonUtils.getCurrentMs(); mFirstAttempt = false; return true; } return false; } TimeoutRefresh(long refreshPeriodMs); @Override boolean attempt();  }