Code example for ListenableFuture

Methods: getisDone

0
   * 
   * @return true if the specified future has been resolved without throwing an exception or being 
   *     cancelled. 
   */ 
  public static boolean isSuccess(ListenableFuture<?> future) throws InterruptedException {
    if (!future.isDone()) {
      return false; 
    } 
 
    try { 
      // Try to get the future, but ignore (and preserve) the thread interrupted state. 
      // This should be fast because we know the future is already complete. 
      future.get();
      return true; 
    } catch (ExecutionException e) {
      // The computation threw an exception, so it did not complete successfully. 
      return false; 
    } catch (CancellationException e) {
      // The computation was cancelled, so it did not complete successfully. 
      return false; 
    } 
  } 
 
  /** 
   * Returns the failure for a {@link ListenableFuture}. 
   * @param future Must have completed unsuccessfully. 
   */ 
  public static Throwable getFailure(ListenableFuture<?> future) throws InterruptedException {
    Preconditions.checkArgument(future.isDone());
    Preconditions.checkArgument(!isSuccess(future));
    try { 
      future.get();
      throw new IllegalStateException("get() should have thrown an exception");
    } catch (ExecutionException e) {
      return e.getCause();
    } catch (CancellationException e) {
      throw new IllegalStateException(e);
Connect your IDE to all the code out there  Get Codota for Java