Window { public List<WindowFuture<K,R,P>> cancelAll() { if (this.futures.size() <= 0) { return null; } List<WindowFuture<K,R,P>> cancelled = new ArrayList<WindowFuture<K,R,P>>(); long now = System.currentTimeMillis(); this.lock.lock(); try { for (DefaultWindowFuture<K,R,P> future : this.futures.values()) { cancelled.add(future); future.cancelHelper(now); } if (cancelled.size() > 0) { this.futures.clear(); this.completedCondition.signalAll(); } } finally { this.lock.unlock(); } return cancelled; } Window(int size);  Window(int size, ScheduledExecutorService executor, long monitorInterval, WindowListener<K,R,P> listener);  Window(int size, ScheduledExecutorService executor, long monitorInterval, WindowListener<K,R,P> listener, String monitorThreadName); int getMaxSize(); int getSize(); int getFreeSize(); boolean containsKey(K key); WindowFuture<K,R,P> get(K key); void addListener(WindowListener<K,R,P> listener); void removeListener(WindowListener<K,R,P> listener); synchronized void destroy(); synchronized boolean startMonitor(); synchronized void stopMonitor(); Map<K,WindowFuture<K,R,P>> createSortedSnapshot(); WindowFuture offer(K key, R request, long offerTimeoutMillis); WindowFuture offer(K key, R request, long offerTimeoutMillis, long expireTimeoutMillis); WindowFuture offer(K key, R request, long offerTimeoutMillis, long expireTimeoutMillis, boolean callerWaitingHint); int getPendingOfferCount(); boolean abortPendingOffers(); WindowFuture<K,R,P> complete(K key, P response); WindowFuture<K,R,P> fail(K key, Throwable t); List<WindowFuture<K,R,P>> failAll(Throwable t); WindowFuture<K,R,P> cancel(K key); List<WindowFuture<K,R,P>> cancelAll(); List<WindowFuture<K,R,P>> cancelAllExpired();  }
@Test public void cancelAll() throws Exception { int count = 5; Window<Integer,String,String> window = new Window<Integer,String,String>(count); String[] requests = new String[count]; for (int i = 0; i < count; i++) { requests[i] = "Request" + i; } for (int i = 0; i < 3; i++) { window.offer(i, requests[i], 100); } Assert.assertEquals(3, window.getSize()); List<WindowFuture<Integer,String,String>> cancelled = window.cancelAll(); Assert.assertEquals(0, window.getSize()); Assert.assertEquals(3, cancelled.size()); for (int i = 0; i < 3; i++) { WindowFuture<Integer,String,String> value = cancelled.get(i); Assert.assertEquals("Request"+value.getKey(), value.getRequest()); Assert.assertEquals(true, value.getAcceptTimestamp() > 0); Assert.assertEquals(null, value.getResponse()); Assert.assertEquals(true, value.getDoneTimestamp() > 0); Assert.assertEquals(true, value.isCancelled()); Assert.assertEquals(true, value.isDone()); Assert.assertEquals(false, value.isSuccess()); } }