@Test public void testExpire() throws InterruptedException { startTime = System.currentTimeMillis(); long ttl = wheel.add("test-1"); while(endTime == 0); long deviation = (endTime - startTime) - ttl; LOG.debug("[CRAFT-ATOM-UTIL] Timing wheel deviation={}", deviation); Assert.assertTrue(deviation <= 2); Assert.assertTrue(deviation >= -2); System.out.println(String.format("[CRAFT-ATOM-UTIL] (^_^) <%s> Case -> test timing wheel expire. ", CaseCounter.incr(2))); }
public long add(E e) { synchronized(e) { checkAdd(e); int previousTickIndex = getPreviousTickIndex(); Slot<E> slot = wheel.get(previousTickIndex); slot.add(e); indicator.put(e, slot); return (ticksPerWheel - 1) * tickDuration; } }
TimingWheel { public long add(E e) { synchronized(e) { checkAdd(e); int previousTickIndex = getPreviousTickIndex(); Slot<E> slot = wheel.get(previousTickIndex); slot.add(e); indicator.put(e, slot); return (ticksPerWheel - 1) * tickDuration; } } }
TimingWheel { public long add(E e) { synchronized(e) { checkAdd(e); int previousTickIndex = getPreviousTickIndex(); Slot<E> slot = wheel.get(previousTickIndex); slot.add(e); indicator.put(e, slot); return (ticksPerWheel - 1) * tickDuration; } } TimingWheel(int tickDuration, int ticksPerWheel, TimeUnit timeUnit); }
TimingWheel { public long add(E e) { synchronized(e) { checkAdd(e); int previousTickIndex = getPreviousTickIndex(); Slot<E> slot = wheel.get(previousTickIndex); slot.add(e); indicator.put(e, slot); return (ticksPerWheel - 1) * tickDuration; } } TimingWheel(int tickDuration, int ticksPerWheel, TimeUnit timeUnit); void start(); boolean stop(); void addExpirationListener(ExpirationListener<E> listener); void removeExpirationListener(ExpirationListener<E> listener); long add(E e); boolean remove(E e); int size(); Set<E> elements(); }
TimingWheel { public long add(E e) { synchronized(e) { checkAdd(e); int previousTickIndex = getPreviousTickIndex(); Slot<E> slot = wheel.get(previousTickIndex); slot.add(e); indicator.put(e, slot); return (ticksPerWheel - 1) * tickDuration; } } TimingWheel(int tickDuration, int ticksPerWheel, TimeUnit timeUnit); void start(); boolean stop(); void addExpirationListener(ExpirationListener<E> listener); void removeExpirationListener(ExpirationListener<E> listener); long add(E e); boolean remove(E e); int size(); Set<E> elements();  }