@Test(expected = TimeoutException.class) public void testWaitForWithTimeout() throws Exception { CounterWait waiter = new CounterWait(1, TimeUnit.MILLISECONDS); waiter.waitFor(1); }
public long waitFor(long value) throws InterruptedException, TimeoutException { if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } ValueEvent eid = new ValueEvent(value); waiters.put(eid); if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } LOGGER.debug("Blocked, waiting for value {}", value); eid.waitFor(); return currentId.get(); }
CounterWait { public long waitFor(long value) throws InterruptedException, TimeoutException { if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } ValueEvent eid = new ValueEvent(value); waiters.put(eid); if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } LOGGER.debug("Blocked, waiting for value {}", value); eid.waitFor(); return currentId.get(); } }
CounterWait { public long waitFor(long value) throws InterruptedException, TimeoutException { if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } ValueEvent eid = new ValueEvent(value); waiters.put(eid); if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } LOGGER.debug("Blocked, waiting for value {}", value); eid.waitFor(); return currentId.get(); } CounterWait();  CounterWait(long waitTimeoutSec);  CounterWait(long waitTimeout, TimeUnit waitTimeUnit); }
CounterWait { public long waitFor(long value) throws InterruptedException, TimeoutException { if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } ValueEvent eid = new ValueEvent(value); waiters.put(eid); if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } LOGGER.debug("Blocked, waiting for value {}", value); eid.waitFor(); return currentId.get(); } CounterWait();  CounterWait(long waitTimeoutSec);  CounterWait(long waitTimeout, TimeUnit waitTimeUnit); synchronized void update(long newValue); synchronized void reset(long newValue); long waitFor(long value); @Override String toString(); int waitersCount(); }
CounterWait { public long waitFor(long value) throws InterruptedException, TimeoutException { if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } ValueEvent eid = new ValueEvent(value); waiters.put(eid); if (value <= currentId.get()) { LOGGER.debug("Value {} reached", value); return currentId.get(); } LOGGER.debug("Blocked, waiting for value {}", value); eid.waitFor(); return currentId.get(); } CounterWait();  CounterWait(long waitTimeoutSec);  CounterWait(long waitTimeout, TimeUnit waitTimeUnit); synchronized void update(long newValue); synchronized void reset(long newValue); long waitFor(long value); @Override String toString(); int waitersCount();  }