/// <param name="client">the client</param> /// <param name="path">path to reap children from</param> /// <param name="executor">executor to use for background tasks</param> /// <param name="reapingThresholdMs">threshold in milliseconds that determines that a path can be deleted /// </param> /// <param name="mode">reaping mode</param> /// <param name="leaderPath">if not null, uses a leader selection so that only 1 reaper is active in the cluster /// </param> public ChildReaper(CuratorFramework client, string path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, string leaderPath) { this.client = client; this.mode = mode; this.executor = new CloseableScheduledExecutorService(executor); this.reapingThresholdMs = reapingThresholdMs; this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath); AddPath(path); }
public void testCloseableScheduleWithFixedDelay() { CloseableScheduledExecutorService service = new CloseableScheduledExecutorService(executorService); CountdownEvent latch = new CountdownEvent(1); service.scheduleWithFixedDelay(RunnableUtils.FromFunc(() => latch.Signal()), DELAY_MS, DELAY_MS ); Assert.True(latch.Wait((QTY * 2) * DELAY_MS)); }
public void testCloseableScheduleWithFixedDelayAndAdditionalTasks() { AtomicInteger outerCounter = new AtomicInteger(0); IRunnable command = RunnableUtils.FromFunc(() => { Console.WriteLine("--"); outerCounter.IncrementAndGet(); }); executorService.scheduleWithFixedDelay(command, DELAY_MS, DELAY_MS); CloseableScheduledExecutorService service = new CloseableScheduledExecutorService(executorService); AtomicInteger innerCounter = new AtomicInteger(0); service.scheduleWithFixedDelay(RunnableUtils.FromFunc(() => { Console.WriteLine("!!"); innerCounter.IncrementAndGet(); }), DELAY_MS, DELAY_MS); Thread.Sleep(DELAY_MS * 4); service.Dispose(); Thread.Sleep(DELAY_MS * 2); Assert.AreEqual(0, service.size()); int innerValue = innerCounter.Get(); Assert.True(innerValue > 0); int value = outerCounter.Get(); Thread.Sleep(DELAY_MS * 2); int newValue = outerCounter.Get(); Assert.True(newValue > value); Assert.AreEqual(innerValue, innerCounter.Get()); value = newValue; Thread.Sleep(DELAY_MS * 2); newValue = outerCounter.Get(); Assert.True(newValue > value); Assert.AreEqual(innerValue, innerCounter.Get()); }