Example usage for com.google.common.util.concurrent Uninterruptibles getUninterruptibly

List of usage examples for com.google.common.util.concurrent Uninterruptibles getUninterruptibly

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Uninterruptibles getUninterruptibly.

Prototype

public static <V> V getUninterruptibly(Future<V> future) throws ExecutionException 

Source Link

Usage

From source file:info.archinnov.achilles.internals.types.EntityIteratorWrapper.java

public EntityIteratorWrapper(CompletableFuture<ResultSet> futureRS, AbstractEntityProperty<ENTITY> meta,
        StatementWrapper statementWrapper, Options options) {
    this.meta = meta;
    this.statementWrapper = statementWrapper;
    this.options = options;
    try {/*from   w  w w.  j  ava  2  s .c om*/
        this.delegate = Uninterruptibles.getUninterruptibly(futureRS.thenApply(options::resultSetAsyncListener)
                .thenApply(statementWrapper::logTrace).thenApply(rs -> rs.iterator()));
    } catch (ExecutionException e) {
        throw extractCauseFromExecutionException(e);
    }
}

From source file:webchat.client.http.FutureAdapter.java

@Override
public V getUninterruptibly() throws IOException {
    try {//w  ww  .  ja va  2 s.  c  o  m
        return Uninterruptibles.getUninterruptibly(wrappedFut);
    } catch (ExecutionException e) {
        Throwable ec = e.getCause();
        if (ec instanceof IOException) {
            throw (IOException) ec;
        }
        throw new RuntimeException(ec);
    }
}

From source file:info.archinnov.achilles.internals.dsl.action.SelectAction.java

/**
 * Execute the SELECT action/*from   w w  w . j av a 2 s  .c o  m*/
 * and return the first entity instance
 */
default ENTITY getOne() {
    try {
        return Uninterruptibles.getUninterruptibly(getOneAsync());
    } catch (ExecutionException e) {
        throw extractCauseFromExecutionException(e);
    }
}

From source file:info.archinnov.achilles.internals.dsl.action.SelectJSONAction.java

/**
 * Execute the SELECT JSON * action/*from   w ww . java  2s .c  o m*/
 * and return the first row value as JSON
 */
default String getJSON() {
    try {
        return Uninterruptibles.getUninterruptibly(getJSONAsync());
    } catch (ExecutionException e) {
        throw extractCauseFromExecutionException(e);
    }
}

From source file:com.datastax.driver.core.ChainedResultSetFuture.java

@Override
public ResultSet getUninterruptibly() {
    try {// ww w  . j  ava  2s  .  c  o m
        return Uninterruptibles.getUninterruptibly(this);
    } catch (ExecutionException e) {
        throw DriverThrowables.propagateCause(e);
    }
}

From source file:com.datastax.driver.core.AbstractSession.java

/**
 * {@inheritDoc}//from www. ja v  a 2 s . c  o  m
 */
@Override
public PreparedStatement prepare(String query) {
    try {
        return Uninterruptibles.getUninterruptibly(prepareAsync(query));
    } catch (ExecutionException e) {
        throw DefaultResultSetFuture.extractCauseFromExecutionException(e);
    }
}

From source file:main.java.hintcommit.futures.DefaultStringFuture.java

/**
 * Waits for the query to return and return its result.
 *
 * This method is usually more convenient than {@link #get} because it:
 * <ul>/*  w w w . j av a 2s .  c  o  m*/
 *   <li>Waits for the result uninterruptibly, and so doesn't throw
 *   {@link InterruptedException}.</li>
 *   <li>Returns meaningful exceptions, instead of having to deal
 *   with ExecutionException.</li>
 * </ul>
 * As such, it is the preferred way to get the future result.
 *
 * @throws NoHostAvailableException if no host in the cluster can be
 * contacted successfully to execute this query.
 * @throws QueryExecutionException if the query triggered an execution
 * exception, that is an exception thrown by Cassandra when it cannot execute
 * the query with the requested consistency level successfully.
 * @throws QueryValidationException if the query is invalid (syntax error,
 * unauthorized or any other validation problem).
 */
public String getUninterruptibly() {
    try {
        return Uninterruptibles.getUninterruptibly(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.facebook.buck.util.concurrent.MoreFutures.java

/**
 * Create a convenience method for checking whether a future completed successfully because this
 * does not appear to be possible to do in a more direct way:
 * https://groups.google.com/forum/?fromgroups=#!topic/guava-discuss/rofEhagKnOc.
 *
 * @return true if the specified future has been resolved without throwing an exception or being
 *     cancelled.//from w  ww  .j a  v a2  s.c  om
 */
public static boolean isSuccess(ListenableFuture<?> future) {
    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.
        Uninterruptibles.getUninterruptibly(future);
        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;
    }
}

From source file:org.grouplens.lenskit.util.parallel.ExecHelpers.java

/**
 * Wait for all futures to finish.//from w  ww  . j  a v  a2 s.  c  o  m
 *
 * @param results The futures to wait on.
 * @throws ExecutionException if one or more futures failed. Remaining
 *                            futures are not waited for.
 * @review Should we wait for all futures, then throw all the errors
 * together?
 */
public static void waitAll(List<Future<?>> results) throws ExecutionException {
    for (Future<?> f : results) {
        Uninterruptibles.getUninterruptibly(f);
    }
}

From source file:zipkin2.storage.cassandra.internal.call.ResultSetFutureCall.java

static ResultSet getUninterruptibly(ListenableFuture<ResultSet> future) {
    if (future instanceof ResultSetFuture) {
        return ((ResultSetFuture) future).getUninterruptibly();
    }/*from  w w w .  j  av a 2 s . co  m*/
    try { // emulate ResultSetFuture.getUninterruptibly
        return Uninterruptibles.getUninterruptibly(future);
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof Error)
            throw ((Error) cause);
        if (cause instanceof DriverException)
            throw ((DriverException) cause).copy();
        throw new DriverInternalError("Unexpected exception thrown", cause);
    }
}