@Test public void testAdd() throws InterruptedException { startTime = System.currentTimeMillis(); long ttl = wheel.add("test-0"); LOG.debug("[CRAFT-ATOM-UTIL] Add object test-0 to timing wheel, will timeout after {} ms, start time={}", ttl, new Date(startTime)); for (int i = 1; i <= 30; i++) { Thread.sleep(10); wheel.add("test-" + i); } Assert.assertEquals(31, wheel.size()); System.out.println(String.format("[CRAFT-ATOM-UTIL] (^_^) <%s> Case -> test timing wheel add. ", CaseCounter.incr(1))); }
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();  }