本文整理汇总了Java中com.google.common.util.concurrent.Futures.getChecked方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.getChecked方法的具体用法?Java Futures.getChecked怎么用?Java Futures.getChecked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.Futures
的用法示例。
在下文中一共展示了Futures.getChecked方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
/** Stops receiving messages from the inspector and closes it. */
@Override
public void close() throws IOException {
try {
// Canceling the future marks the future done and the messenger "closed".
// If it can't be cancelled, it must have terminated prematurely, so raise an exception.
if (!receiveFuture.cancel(false)) {
Futures.getChecked(receiveFuture, IOException.class);
}
} finally {
try {
MoreExecutors.shutdownAndAwaitTermination(executor, 5, SECONDS);
} finally {
inspector.close();
}
}
}
示例2: doStage
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
StageCallResults doStage() {
List<ListenableFuture<StagedPackage>> uploadFutures = classpathElements.stream()
.filter(classpathElement -> {
File file = new File(classpathElement);
if (!file.exists()) {
LOG.warn("Skipping non-existent classpath element {} that was specified.",
classpathElement);
return false;
} else {
return true;
}
})
.map(this::uploadClasspathElement)
.collect(toList());
List<StagedPackage> stagedPackages;
try {
stagedPackages = Futures.getChecked(
Futures.allAsList(uploadFutures),
IOException.class,
UPLOAD_TIMEOUT_MINUTES, MINUTES);
} catch (IOException e) {
throw new RuntimeException(e);
}
// How many of these were uploaded by us vs. other calls
int numUploaded = (int) stagedPackages.stream().filter(p -> p.stageCallId() == id).count();
int numCached = (int) stagedPackages.stream().filter(p -> p.stageCallId() != id).count();
return stageCallResults(stagedPackages, numUploaded, numCached);
}
示例3: futuresGetChecked
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Benchmark
void futuresGetChecked(int n) {
IOException exception = new IOException();
CompletableFuture<?> future = new CompletableFuture<>();
future.completeExceptionally(exception);
for (int i = 0; i < n; i++) {
try {
Futures.getChecked(future, IOException.class);
throw new AssertionError();
} catch (IOException expected) {}
}
}
示例4: sendCommand
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
/**
* Sends a command to the debugger and returns the result.
*
* @throws DevtoolsErrorException - if the command caused an error in the debugger.
* @throws IOException - if an I/O error occurred.
*/
public final DevtoolsResult sendCommand(DevtoolsCommand command, Duration timeout)
throws IOException, DevtoolsErrorException {
CommandFuture future = sendCommandAsync(command);
try {
JsonObject response =
Futures.getChecked(future, IOException.class, timeout.toNanos(), NANOSECONDS);
return convertResponseToResult(command, response);
} catch (IOException e) {
idToFuture.remove(future.id());
throw e;
}
}