Java Code Examples for com.google.common.util.concurrent.Futures#getChecked()

The following examples show how to use com.google.common.util.concurrent.Futures#getChecked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DremioFutures.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Dremio version of Guava's Futures.getChecked without timeout.
 *
 * @param future         Future to get from
 * @param exceptionClass Exception Class to throw
 * @param mapper         Function to map original exception to exceptionClass
 */
public static <T, X extends Exception> T getChecked(
  Future<T> future,
  Class<X> exceptionClass,
  Function<? super Throwable, ? extends X> mapper
) throws X {
  try {
    return Futures.getChecked(future, ExecutionException.class);
  } catch (ExecutionException e) {
    try {
      handleException(e, exceptionClass, mapper);
      throw new AssertionError();
    } catch (TimeoutException ex) {
      throw new AssertionError();
    }
  }
}
 
Example 2
Source File: DremioFutures.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Dremio version of Guava's Futures.getChecked with timeout. Throws TimeoutException
 * directly instead of hiding it.
 *
 * @param future         Future to get from
 * @param exceptionClass Exception Class to throw
 * @param timeout        Timeout amount
 * @param unit           Timeout units
 * @param mapper         Function to map original exception to exceptionClass
 */
public static <T, X extends Exception> T getChecked(
  Future<T> future,
  Class<X> exceptionClass,
  long timeout,
  TimeUnit unit,
  Function<? super Throwable, ? extends X> mapper
) throws TimeoutException, X {
  try {
    return Futures.getChecked(future, ExecutionException.class, timeout, unit);
  } catch (ExecutionException e) {
    handleException(e, exceptionClass, mapper);
    throw new AssertionError();
  }
}
 
Example 3
Source File: ExceptionWrappingBenchmark.java    From mug with Apache License 2.0 5 votes vote down vote up
@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) {}
  }
}
 
Example 4
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final Query statement, final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 5
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final Query statement) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement), DatastoreException.class);
}
 
Example 6
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public MutationResult execute(final Batch batch, final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync(batch, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 7
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public MutationResult execute(final Batch batch) throws DatastoreException {
  return Futures.getChecked(executeAsync(batch), DatastoreException.class);
}
 
Example 8
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public MutationResult execute(final MutationStatement statement, final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 9
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public MutationResult execute(final MutationStatement statement) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement), DatastoreException.class);
}
 
Example 10
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final List<KeyQuery> statements, final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync(statements, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 11
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final KeyQuery statement, final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 12
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final List<KeyQuery> statements) throws DatastoreException {
  return Futures.getChecked(executeAsync(statements), DatastoreException.class);
}
 
Example 13
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult execute(final KeyQuery statement) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement), DatastoreException.class);
}
 
Example 14
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public AllocateIdsResult execute(final AllocateIds statement) throws DatastoreException {
  return Futures.getChecked(executeAsync(statement), DatastoreException.class);
}
 
Example 15
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public MutationResult commit(final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(executeAsync((MutationStatement) null, Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 16
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public RollbackResult rollback(final TransactionResult txn) throws DatastoreException {
  return Futures.getChecked(rollbackAsync(Futures.immediateFuture(txn)), DatastoreException.class);
}
 
Example 17
Source File: DatastoreImpl.java    From async-datastore-client with Apache License 2.0 4 votes vote down vote up
@Override
public TransactionResult transaction() throws DatastoreException {
  return Futures.getChecked(transactionAsync(), DatastoreException.class);
}