List of usage examples for com.google.common.util.concurrent Futures allAsList
@Beta @CheckReturnValue public static <V> ListenableFuture<List<V>> allAsList( Iterable<? extends ListenableFuture<? extends V>> futures)
From source file:c5db.ConcurrencyTestUtil.java
private static void waitForAll(List<ListenableFuture<Boolean>> futures) throws Exception { Futures.allAsList(futures).get(); }
From source file:com.google.idea.blaze.base.prefetch.PrefetchServiceImpl.java
@Override public ListenableFuture<?> prefetchFiles(Project project, Collection<File> files) { List<ListenableFuture<?>> futures = Lists.newArrayList(); for (Prefetcher prefetcher : Prefetcher.EP_NAME.getExtensions()) { futures.add(prefetcher.prefetchFiles(project, files, FetchExecutor.EXECUTOR)); }// www. j a va 2s.c o m return Futures.allAsList(futures); }
From source file:com.google.gapid.models.ConstantSets.java
public ListenableFuture<List<Service.ConstantSet>> loadConstants(Service.Command cmd) { List<ListenableFuture<Service.ConstantSet>> sets = Lists.newArrayList(); for (Service.Parameter param : cmd.getParametersList()) { if (param.hasConstants()) { sets.add(cache.get(param.getConstants())); }/*from w w w . java 2s. c o m*/ } return Futures.allAsList(sets); }
From source file:org.robotninjas.concurrent.FluentFutures.java
/** * * @param executor/* w w w . j av a 2s . co m*/ * @param futures * @param <Y> * @return */ @SafeVarargs public static <Y> FluentFuture<List<Y>> from(Executor executor, ListenableFuture<Y>... futures) { return new FluentDecorator<>(Futures.allAsList(Arrays.asList(futures)), executor); }
From source file:com.facebook.presto.operator.ParallelLookupSourceSupplier.java
public ParallelLookupSourceSupplier(List<Type> types, List<Integer> hashChannels, List<? extends ListenableFuture<SharedLookupSource>> partitions) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); this.partitions = requireNonNull(partitions, "partitions is null"); hashChannelTypes = hashChannels.stream().map(types::get).collect(toImmutableList()); checkArgument(Integer.bitCount(partitions.size()) == 1, "partitions must be a power of 2"); lookupSourceFuture = Futures.transform(Futures.allAsList(partitions), (List<SharedLookupSource> input) -> { return new PartitionedLookupSource(input, hashChannelTypes); });/*from ww w .j ava 2 s . c om*/ }
From source file:com.google.devtools.build.lib.concurrent.MoreFutures.java
/** * Creates a new {@code ListenableFuture} whose value is a list containing the * values of all its input futures, if all succeed. If any input fails, the * returned future fails. If any of the futures fails, it cancels all the other futures. * * <p> This method is similar to {@code Futures.allAsList} but additionally it cancels all the * futures in case any of them fails.//from w w w. ja v a2s. c om */ public static <V> ListenableFuture<List<V>> allAsListOrCancelAll( final Iterable<? extends ListenableFuture<? extends V>> futures) { ListenableFuture<List<V>> combinedFuture = Futures.allAsList(futures); Futures.addCallback(combinedFuture, new FutureCallback<List<V>>() { @Override public void onSuccess(@Nullable List<V> vs) { } /** * In case of a failure of any of the futures (that gets propagated to combinedFuture) we * cancel all the futures in the list. */ @Override public void onFailure(Throwable ignore) { for (ListenableFuture<? extends V> future : futures) { future.cancel(true); } } }); return combinedFuture; }
From source file:com.datastax.driver.mapping.AccessorMapper.java
void prepare(MappingManager manager) { List<ListenableFuture<PreparedStatement>> statements = new ArrayList<ListenableFuture<PreparedStatement>>( methods.size());/* w w w.j a v a2 s . co m*/ for (MethodMapper method : methods) statements.add(manager.getSession().prepareAsync(method.queryString)); try { List<PreparedStatement> preparedStatements = Futures.allAsList(statements).get(); for (int i = 0; i < methods.size(); i++) methods.get(i).prepare(manager, preparedStatements.get(i)); } catch (Exception e) { throw new RuntimeException("Error preparing queries for accessor " + daoClass.getSimpleName(), e); } }
From source file:com.android.tools.idea.run.DeviceFutures.java
/** @return the target devices, if all are now ready. Otherwise, null. */ @Nullable/*from w w w . j av a2 s. co m*/ public List<IDevice> getIfReady() { List<ListenableFuture<IDevice>> devices = get(); for (ListenableFuture<IDevice> deviceFuture : devices) { if (!deviceFuture.isDone() || deviceFuture.isCancelled()) { return null; } } try { return Futures.getChecked(Futures.allAsList(devices), ExecutionException.class); } catch (Exception e) { // This can happen if the process behind the future threw an exception. return null; } }
From source file:io.crate.executor.transport.task.UpdateTask.java
@Override public void start() { if (subTasks.size() == 0) { result.set(RowCountResult.EMPTY_RESULT); return;//from www.jav a 2s. c o m } final List<ListenableFuture<TaskResult>> subTasksResult = transportExecutor.execute(subTasks); Futures.addCallback(Futures.allAsList(subTasksResult), new FutureCallback<List<TaskResult>>() { @Override public void onSuccess(@Nullable List<TaskResult> results) { if (results == null) { result.setException(new NullPointerException()); return; } assert results.size() == 1 : "Last sub-task is expected to have 1 result only"; result.set(new RowCountResult(((Number) results.get(0).rows()[0][0]).longValue())); } @Override public void onFailure(@Nonnull Throwable t) { if (t == null) { t = new NullPointerException(); } result.setException(t); } }); }
From source file:io.crate.executor.transport.task.AbstractChainedTask.java
@Override public void start() { if (!this.upstreamResult.isEmpty()) { Futures.addCallback(Futures.allAsList(this.upstreamResult), new FutureCallback<List<TaskResult>>() { @Override/* w w w . j ava 2 s . com*/ public void onSuccess(@Nullable List<TaskResult> result) { doStart(result); } @Override public void onFailure(@Nonnull Throwable t) { throw new TaskExecutionException(AbstractChainedTask.this, t); } }); } else { doStart(ImmutableList.<TaskResult>of()); } }