@Test public void testFailed() throws Exception { final BasicFutureCallback<Object> callback = new BasicFutureCallback<>(); final BasicFuture<Object> future = new BasicFuture<>(callback); final Object result = new Object(); final Exception boom = new Exception(); future.failed(boom); future.completed(result); Assert.assertFalse(callback.isCompleted()); Assert.assertNull(callback.getResult()); Assert.assertTrue(callback.isFailed()); Assert.assertSame(boom, callback.getException()); Assert.assertFalse(callback.isCancelled()); try { future.get(); } catch (final ExecutionException ex) { Assert.assertSame(boom, ex.getCause()); } Assert.assertTrue(future.isDone()); Assert.assertFalse(future.isCancelled()); }
public boolean failed(final Exception exception) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.ex = exception; notifyAll(); } if (this.callback != null) { this.callback.failed(exception); } return true; }
BasicFuture implements Future<T>, Cancellable { public boolean failed(final Exception exception) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.ex = exception; notifyAll(); } if (this.callback != null) { this.callback.failed(exception); } return true; } }
BasicFuture implements Future<T>, Cancellable { public boolean failed(final Exception exception) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.ex = exception; notifyAll(); } if (this.callback != null) { this.callback.failed(exception); } return true; } BasicFuture(final FutureCallback<T> callback); }
BasicFuture implements Future<T>, Cancellable { public boolean failed(final Exception exception) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.ex = exception; notifyAll(); } if (this.callback != null) { this.callback.failed(exception); } return true; } BasicFuture(final FutureCallback<T> callback); @Override boolean isCancelled(); @Override boolean isDone(); @Override synchronized T get(); @Override synchronized T get(final long timeout, final TimeUnit unit); boolean completed(final T result); boolean failed(final Exception exception); @Override boolean cancel(final boolean mayInterruptIfRunning); @Override boolean cancel(); }
BasicFuture implements Future<T>, Cancellable { public boolean failed(final Exception exception) { synchronized(this) { if (this.completed) { return false; } this.completed = true; this.ex = exception; notifyAll(); } if (this.callback != null) { this.callback.failed(exception); } return true; } BasicFuture(final FutureCallback<T> callback); @Override boolean isCancelled(); @Override boolean isDone(); @Override synchronized T get(); @Override synchronized T get(final long timeout, final TimeUnit unit); boolean completed(final T result); boolean failed(final Exception exception); @Override boolean cancel(final boolean mayInterruptIfRunning); @Override boolean cancel();  }