@Test public void testIntervalTimes() throws InterruptedException { startTime = ThreadLocalRandom.current().nextLong(); buffer = new CircularBuffer<>(4, TimeUnit.SECONDS.toNanos(1), startTime); final CountDownLatch latch = new CountDownLatch(5); ExecutorService es = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; ++i) { es.submit(getRunnable(latch)); } latch.await(); long remainder = TimeUnit.MILLISECONDS.toNanos(ThreadLocalRandom.current().nextLong(1000)); long nanoTime = startTime + TimeUnit.SECONDS.toNanos(5) + remainder; IntervalIterator<AtomicLong> intervals = buffer.intervals(nanoTime, new AtomicLong(0)); int i = 3; while (intervals.hasNext()) { assertEquals(-(i * TimeUnit.SECONDS.toNanos(1) + remainder), intervals.intervalStart()); long intervalEnd = -((i - 1) * TimeUnit.SECONDS.toNanos(1) + remainder); assertEquals(intervalEnd < 0 ? intervalEnd : 0, intervals.intervalEnd()); intervals.next(); --i; } }
public IntervalIterator<T> intervals(long nanoTime, T dead) { Intervals intervals = new Intervals(dead); intervals.reset(nanoTime); return intervals; }
CircularBuffer { public IntervalIterator<T> intervals(long nanoTime, T dead) { Intervals intervals = new Intervals(dead); intervals.reset(nanoTime); return intervals; } }
CircularBuffer { public IntervalIterator<T> intervals(long nanoTime, T dead) { Intervals intervals = new Intervals(dead); intervals.reset(nanoTime); return intervals; } CircularBuffer(int slotsToTrack, long nanosPerSlot);  CircularBuffer(int slotsToTrack, long nanosPerSlot, long startNanos); }
CircularBuffer { public IntervalIterator<T> intervals(long nanoTime, T dead) { Intervals intervals = new Intervals(dead); intervals.reset(nanoTime); return intervals; } CircularBuffer(int slotsToTrack, long nanosPerSlot);  CircularBuffer(int slotsToTrack, long nanosPerSlot, long startNanos); T getSlot(long nanoTime); T putOrGet(long nanoTime, T object); IntervalIterator<T> intervals(long nanoTime, T dead); }
CircularBuffer { public IntervalIterator<T> intervals(long nanoTime, T dead) { Intervals intervals = new Intervals(dead); intervals.reset(nanoTime); return intervals; } CircularBuffer(int slotsToTrack, long nanosPerSlot);  CircularBuffer(int slotsToTrack, long nanosPerSlot, long startNanos); T getSlot(long nanoTime); T putOrGet(long nanoTime, T object); IntervalIterator<T> intervals(long nanoTime, T dead);  }