Window { public WindowFuture<K,R,P> cancel(K key) throws InterruptedException { if (!this.futures.containsKey(key)) { return null; } this.lock.lockInterruptibly(); try { DefaultWindowFuture<K,R,P> future = this.futures.remove(key); if (future == null) { return null; } future.cancelHelper(System.currentTimeMillis()); this.completedCondition.signalAll(); return future; } finally { this.lock.unlock(); } } 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 cancel() throws Exception { Window<Integer,String,String> window = new Window<Integer,String,String>(1); Integer i = new Integer(1); String request = "Request"+i; WindowFuture<Integer,String,String> requestFuture = window.offer(i, request, 100); WindowFuture<Integer,String,String> responseFuture = window.cancel(i); Assert.assertEquals(new Integer(i), responseFuture.getKey()); Assert.assertEquals(request, responseFuture.getRequest()); Assert.assertEquals(true, responseFuture.getAcceptTimestamp() > 0); Assert.assertEquals(null, responseFuture.getResponse()); Assert.assertEquals(true, responseFuture.getDoneTimestamp() > 0); Assert.assertEquals(true, requestFuture.isCancelled()); Assert.assertEquals(true, requestFuture.isDone()); Assert.assertEquals(false, requestFuture.isSuccess()); Assert.assertTrue(requestFuture.getAcceptToDoneTime() >= 0); Assert.assertTrue(requestFuture.await(50)); }