com.google.common.util.concurrent.AbstractFuture.setException()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(46)

本文整理了Java中com.google.common.util.concurrent.AbstractFuture.setException()方法的一些代码示例,展示了AbstractFuture.setException()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFuture.setException()方法的具体详情如下:
包路径:com.google.common.util.concurrent.AbstractFuture
类名称:AbstractFuture
方法名:setException

AbstractFuture.setException介绍

[英]Sets the failed result of this Future unless this Future has already been cancelled or set (including #setFuture). When a call to this method returns, the Future is guaranteed to be #isDone only if the call was accepted (in which case it returns true). If it returns false, the Future may have previously been set asynchronously, in which case its result may not be known yet. That result, though not yet known, cannot be overridden by a call to a setmethod, only by a call to #cancel.
[中]设置此未来的失败结果,除非此未来已被取消或设置(包括#setFuture)。当对该方法的调用返回时,只有在该调用被接受的情况下(在这种情况下,它返回true),未来才会被保证为#isDone。如果返回false,则Future可能以前是异步设置的,在这种情况下,其结果可能还未知。这个结果虽然还不知道,但不能通过调用set
方法来覆盖,只能通过调用#cancel来覆盖。

代码示例

代码示例来源:origin: prestodb/presto

@Override
protected boolean setException(Throwable throwable)
{
  return super.setException(throwable);
}

代码示例来源:origin: apache/incubator-druid

@Override
public boolean setException(Throwable throwable)
{
 return super.setException(throwable);
}

代码示例来源:origin: apache/incubator-druid

@Override
public boolean setException(Throwable throwable)
{
 return super.setException(throwable);
}

代码示例来源:origin: thinkaurelius/titan

/**
 * This method should be called by {@Link Log} implementations when the message could not be added to the log
 * with the respective exception object.
 * @param exception
 */
public void failed(Throwable exception) {
  super.setException(exception);
}

代码示例来源:origin: JanusGraph/janusgraph

/**
 * This method should be called by {@link org.janusgraph.diskstorage.log.Log} implementations when the message could not be added to the log
 * with the respective exception object.
 * @param exception
 */
public void failed(Throwable exception) {
  super.setException(exception);
}

代码示例来源:origin: google/guava

@Override
 public void execute(final Runnable command) {
  try {
   delegate.execute(
     new Runnable() {
      @Override
      public void run() {
       thrownFromDelegate = false;
       command.run();
      }
     });
  } catch (RejectedExecutionException e) {
   if (thrownFromDelegate) {
    // wrap exception?
    future.setException(e);
   }
   // otherwise it must have been thrown from a transitive call and the delegate runnable
   // should have handled it.
  }
 }
};

代码示例来源:origin: qunarcorp/qmq

@Override
  public void onException(Exception ex) {
    super.setException(ex);
  }
}

代码示例来源:origin: google/j2objc

@Override
 public void execute(final Runnable command) {
  try {
   delegate.execute(
     new Runnable() {
      @Override
      public void run() {
       thrownFromDelegate = false;
       command.run();
      }
     });
  } catch (RejectedExecutionException e) {
   if (thrownFromDelegate) {
    // wrap exception?
    future.setException(e);
   }
   // otherwise it must have been thrown from a transitive call and the delegate runnable
   // should have handled it.
  }
 }
};

代码示例来源:origin: prestodb/presto

@Override
protected boolean setException(Throwable throwable)
{
  return super.setException(throwable);
}

代码示例来源:origin: wildfly/wildfly

@Override
 public void execute(final Runnable command) {
  try {
   delegate.execute(
     new Runnable() {
      @Override
      public void run() {
       thrownFromDelegate = false;
       command.run();
      }
     });
  } catch (RejectedExecutionException e) {
   if (thrownFromDelegate) {
    // wrap exception?
    future.setException(e);
   }
   // otherwise it must have been thrown from a transitive call and the delegate runnable
   // should have handled it.
  }
 }
};

代码示例来源:origin: google/guava

@Override
 public Void call() {
  if (currentFuture.get().setException(failureCause)) {
   numSuccessfulSetCalls.incrementAndGet();
  }
  awaitUnchecked(barrier);
  return null;
 }
};

代码示例来源:origin: google/guava

@Override
 public void run() {
  future.setException(new IllegalArgumentException("failure"));
  if (!future.isDone()) {
   errorMessage.set("SetException call exited before future was complete.");
  }
 }
});

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
 @Override
 public boolean setException(Throwable t) {
  return super.setException(t);
 }
}

代码示例来源:origin: google/guava

public void complete(RuntimeException e) {
 if (!super.setException(new WrapperException(checkNotNull(e)))) {
  throw new IllegalStateException("Future was already complete: " + this);
 }
}

代码示例来源:origin: google/guava

public void complete(Error e) {
 if (!super.setException(new WrapperException(checkNotNull(e)))) {
  throw new IllegalStateException("Future was already complete: " + this);
 }
}

代码示例来源:origin: google/guava

public void testGetFailure_Failed() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 final Throwable failure = new Throwable();
 future.setException(failure);
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

private static void assertCannotSet(AbstractFuture<Integer> future) {
 assertThat(future.set(99)).isFalse();
 assertThat(future.setException(new IndexOutOfBoundsException())).isFalse();
 assertThat(future.setFuture(new AbstractFuture<Integer>() {})).isFalse();
 assertThat(future.setFuture(immediateFuture(99))).isFalse();
}

代码示例来源:origin: google/guava

public void testListenLaterSetAsynchronouslyLaterDelegateFailed() {
 CountingRunnable before = new CountingRunnable();
 CountingRunnable inBetween = new CountingRunnable();
 CountingRunnable after = new CountingRunnable();
 future.addListener(before, directExecutor());
 future.setFuture(delegate);
 future.addListener(inBetween, directExecutor());
 delegate.setException(new Exception());
 future.addListener(after, directExecutor());
 before.assertRun();
 inBetween.assertRun();
 after.assertRun();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public void onException(
  Connection connection, Exception exception, long latency, int retryCount) {
 // If all nodes are down, we will get a null connection here. This is fine, if we have
 // an exception, consumers shouldn't assume the address is not null.
 if (connection != null) this.address = connection.address;
 super.setException(exception);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public boolean onTimeout(Connection connection, long latency, int retryCount) {
 assert connection
   != null; // We always timeout on a specific connection, so this shouldn't be null
 this.address = connection.address;
 return super.setException(new OperationTimedOutException(connection.address));
}

相关文章