@Test public void shouldRescheduleIfTouched() throws Exception { timeProvider.forwardMillis(75); requestEventBus.triggerEvent(Event.TOUCH); timeProvider.forwardMillis(75); idleTimeoutTimerTask.run(null); verify(requestEventBus, times(0)).triggerEvent(eq(Event.ERROR), eq(httpRequestContext), any(TimeoutException.class)); verify(timeoutTimerHandler).scheduleTimeout( 25, TimeUnit.MILLISECONDS); }
@Override public void run(Timeout timeout) throws Exception { if (completed.get() || canceled.get()) { return; } if (executing.compareAndSet(false, true)) { long now = timeProvider.currentTimeInMillis(); long currentReadTimeoutInstant = maxIdleTime + lastTouched; long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now; if (durationBeforeCurrentReadTimeout <= 0L) { long durationSinceLastTouch = now - lastTouched; String message = "Idle timeout of " + maxIdleTime + " ms was " + durationSinceLastTouch + " ms since last event"; requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new TimeoutException(message)); completed(); } else timeoutTimerHandler.scheduleTimeout(durationBeforeCurrentReadTimeout, TimeUnit.MILLISECONDS); executing.set(false); } }
IdleTimeoutTimerTask implements TimeoutTimerTask { @Override public void run(Timeout timeout) throws Exception { if (completed.get() || canceled.get()) { return; } if (executing.compareAndSet(false, true)) { long now = timeProvider.currentTimeInMillis(); long currentReadTimeoutInstant = maxIdleTime + lastTouched; long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now; if (durationBeforeCurrentReadTimeout <= 0L) { long durationSinceLastTouch = now - lastTouched; String message = "Idle timeout of " + maxIdleTime + " ms was " + durationSinceLastTouch + " ms since last event"; requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new TimeoutException(message)); completed(); } else timeoutTimerHandler.scheduleTimeout(durationBeforeCurrentReadTimeout, TimeUnit.MILLISECONDS); executing.set(false); } } }
IdleTimeoutTimerTask implements TimeoutTimerTask { @Override public void run(Timeout timeout) throws Exception { if (completed.get() || canceled.get()) { return; } if (executing.compareAndSet(false, true)) { long now = timeProvider.currentTimeInMillis(); long currentReadTimeoutInstant = maxIdleTime + lastTouched; long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now; if (durationBeforeCurrentReadTimeout <= 0L) { long durationSinceLastTouch = now - lastTouched; String message = "Idle timeout of " + maxIdleTime + " ms was " + durationSinceLastTouch + " ms since last event"; requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new TimeoutException(message)); completed(); } else timeoutTimerHandler.scheduleTimeout(durationBeforeCurrentReadTimeout, TimeUnit.MILLISECONDS); executing.set(false); } } IdleTimeoutTimerTask(HttpRequestContext httpRequestContext, long maxIdleTime, TimeProvider timeProvider, RequestEventBus requestEventBus); }
IdleTimeoutTimerTask implements TimeoutTimerTask { @Override public void run(Timeout timeout) throws Exception { if (completed.get() || canceled.get()) { return; } if (executing.compareAndSet(false, true)) { long now = timeProvider.currentTimeInMillis(); long currentReadTimeoutInstant = maxIdleTime + lastTouched; long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now; if (durationBeforeCurrentReadTimeout <= 0L) { long durationSinceLastTouch = now - lastTouched; String message = "Idle timeout of " + maxIdleTime + " ms was " + durationSinceLastTouch + " ms since last event"; requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new TimeoutException(message)); completed(); } else timeoutTimerHandler.scheduleTimeout(durationBeforeCurrentReadTimeout, TimeUnit.MILLISECONDS); executing.set(false); } } IdleTimeoutTimerTask(HttpRequestContext httpRequestContext, long maxIdleTime, TimeProvider timeProvider, RequestEventBus requestEventBus); @Override void run(Timeout timeout); @Override void completed(); @Override void cancel(); void setTimeoutTimerHandler(TimeoutTimerHandler timeoutTimerHandler); }
IdleTimeoutTimerTask implements TimeoutTimerTask { @Override public void run(Timeout timeout) throws Exception { if (completed.get() || canceled.get()) { return; } if (executing.compareAndSet(false, true)) { long now = timeProvider.currentTimeInMillis(); long currentReadTimeoutInstant = maxIdleTime + lastTouched; long durationBeforeCurrentReadTimeout = currentReadTimeoutInstant - now; if (durationBeforeCurrentReadTimeout <= 0L) { long durationSinceLastTouch = now - lastTouched; String message = "Idle timeout of " + maxIdleTime + " ms was " + durationSinceLastTouch + " ms since last event"; requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new TimeoutException(message)); completed(); } else timeoutTimerHandler.scheduleTimeout(durationBeforeCurrentReadTimeout, TimeUnit.MILLISECONDS); executing.set(false); } } IdleTimeoutTimerTask(HttpRequestContext httpRequestContext, long maxIdleTime, TimeProvider timeProvider, RequestEventBus requestEventBus); @Override void run(Timeout timeout); @Override void completed(); @Override void cancel(); void setTimeoutTimerHandler(TimeoutTimerHandler timeoutTimerHandler);  }