/** * Construct a new poller which will run on the provided scheduler, and run at the specified * frequency. * <p> * This constructor additionally allows you to specify the maximum time in millseconds we should * wait for the condition to become true. At this point if we are still not seeing our expected * polling state, then the return future will be canceled. * * @param scheduler Scheduler to run polling task on * @param pollFrequency Time in milliseconds to wait between polling events * @param maxWaitTime Maximum time in milliseconds till returned futures should be canceled */ public Poller(SchedulerService scheduler, long pollFrequency, long maxWaitTime) { if (maxWaitTime > 0 && maxWaitTime != Long.MAX_VALUE) { futureWatchdog = new Watchdog(scheduler, maxWaitTime, false); } else { futureWatchdog = null; } this.runner = new PollRunner(scheduler, pollFrequency); }
/** * Construct a new poller which will run on the provided scheduler, and run at the specified * frequency. * <p> * This constructor additionally allows you to specify the maximum time in millseconds we should * wait for the condition to become true. At this point if we are still not seeing our expected * polling state, then the return future will be canceled. * * @param scheduler Scheduler to run polling task on * @param pollFrequency Time in milliseconds to wait between polling events * @param maxWaitTime Maximum time in milliseconds till returned futures should be canceled */ public Poller(SchedulerService scheduler, long pollFrequency, long maxWaitTime) { if (maxWaitTime > 0 && maxWaitTime != Long.MAX_VALUE) { futureWatchdog = new Watchdog(scheduler, maxWaitTime, false); } else { futureWatchdog = null; } this.runner = new PollRunner(scheduler, pollFrequency); }
watchdogProducer = (timeout) -> { maybeScheduleCleaner(); return new Watchdog(scheduler, timeout, sendInterruptOnFutureCancel); }; cacheCleaner = new CleanRunner();
watchdogProducer = (timeout) -> { maybeScheduleCleaner(); return new Watchdog(scheduler, timeout, sendInterruptOnFutureCancel); }; cacheCleaner = new CleanRunner();
@Before public void setup() { scheduler = new NoThreadScheduler(); watchdog = new Watchdog(scheduler, TIMEOUT, true); }
@Test public void rescheduledFutureCheckTest() throws InterruptedException { long delayTime = 100; // longer than constants DELAY_TIME to ensure we can tick BEFORE the second future times out watchdog = new Watchdog(scheduler, delayTime * 2, true); SettableListenableFuture<?> slf1 = new SettableListenableFuture<>(); watchdog.watch(slf1); TestUtils.sleep(delayTime); SettableListenableFuture<?> slf2 = new SettableListenableFuture<>(); watchdog.watch(slf2); assertEquals(1, scheduler.blockingTick(null)); assertTrue(slf1.isCancelled()); assertFalse(slf2.isCancelled()); assertEquals(1, scheduler.blockingTick(null)); assertTrue(slf1.isCancelled()); assertTrue(slf2.isCancelled()); } }