当前位置: 首页>>代码示例>>Java>>正文


Java Futures.getChecked方法代码示例

本文整理汇总了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();
    }
  }
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:18,代码来源:InspectorMessenger.java

示例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);
}
 
开发者ID:spotify,项目名称:hype,代码行数:32,代码来源:StagingUtil.java

示例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) {}
  }
}
 
开发者ID:google,项目名称:mug,代码行数:13,代码来源:ExceptionWrappingBenchmark.java

示例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;
  }
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:19,代码来源:DevtoolsDebugger.java


注:本文中的com.google.common.util.concurrent.Futures.getChecked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。