@Override public <E extends T> CompletableFuture<Iterable<E>> insert(final Iterable<E> entities) { return CompletableFuture.supplyAsync(new Supplier<Iterable<E>>() { @Override public Iterable<E> get() { return delegate.insert(entities); } }, executor); }
public ZkClientWrapper(final String serverAddr, long timeout) { this.timeout = timeout; completableFuture = CompletableFuture.supplyAsync(() -> new ZkClient(serverAddr, Integer.MAX_VALUE)); }
public ZkClientWrapper(final String serverAddr, long timeout) { this.timeout = timeout; completableFuture = CompletableFuture.supplyAsync(() -> new ZkClient(serverAddr, Integer.MAX_VALUE)); }
public static <R> CompletableFuture<List<R>> sequenceSuccessFuture(List<CompletableFuture<R>> futures) { return CompletableFuture.supplyAsync(() -> futures.parallelStream() .map(AsyncUtils::getValue) .filter(Objects::nonNull) .collect(Collectors.toList()) ); }
private Map<StateHandleID, CompletableFuture<StreamStateHandle>> createUploadFutures( Map<StateHandleID, Path> files, CheckpointStreamFactory checkpointStreamFactory, CloseableRegistry closeableRegistry) { Map<StateHandleID, CompletableFuture<StreamStateHandle>> futures = new HashMap<>(files.size()); for (Map.Entry<StateHandleID, Path> entry : files.entrySet()) { final Supplier<StreamStateHandle> supplier = CheckedSupplier.unchecked(() -> uploadLocalFileToCheckpointFs(entry.getValue(), checkpointStreamFactory, closeableRegistry)); futures.put(entry.getKey(), CompletableFuture.supplyAsync(supplier, executorService)); } return futures; }
@Override public CompletionStage<List<Object>> load(List<String> keys) { return CompletableFuture.supplyAsync(() -> getTheseCharacters(keys)); } };
@Override public CompletionStage<List<Object>> load(List<String> keys) { // // we use supplyAsync() of values here for maximum parellisation // return CompletableFuture.supplyAsync(() -> getCharacterDataViaBatchHTTPApi(keys)); } };
@Override protected CompletableFuture<JobPlanInfo> handleRequest( @Nonnull final HandlerRequest<JarPlanRequestBody, JarPlanMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException { final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log); return CompletableFuture.supplyAsync(() -> { final JobGraph jobGraph = context.toJobGraph(configuration); return planGenerator.apply(jobGraph); }, executor); } }
private CompletableFuture<JobGraph> getJobGraphAsync( JarHandlerContext context, final SavepointRestoreSettings savepointRestoreSettings) { return CompletableFuture.supplyAsync(() -> { final JobGraph jobGraph = context.toJobGraph(configuration); jobGraph.setSavepointRestoreSettings(savepointRestoreSettings); return jobGraph; }, executor); } }
private CompletableFuture<Boolean> scheduleBatchOrHandleError( BoltConnection connection ) { try { return CompletableFuture.supplyAsync( () -> executeBatch( connection ), threadPool ); } catch ( RejectedExecutionException ex ) { return failedFuture( ex ); } }
@Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final CompletableFuture<Monitor> completableFuture = CompletableFuture.supplyAsync(() -> AbstractMonitorFactory.this.createMonitor(monitorUrl)); completableFuture.thenRunAsync(new MonitorListener(key), executor); FUTURES.put(key, completableFuture); return null; } finally { // unlock LOCK.unlock(); } }
@Override public Monitor getMonitor(URL url) { url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future<Monitor> future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } LOCK.lock(); try { monitor = MONITORS.get(key); future = FUTURES.get(key); if (monitor != null || future != null) { return monitor; } final URL monitorUrl = url; final CompletableFuture<Monitor> completableFuture = CompletableFuture.supplyAsync(() -> AbstractMonitorFactory.this.createMonitor(monitorUrl)); completableFuture.thenRunAsync(new MonitorListener(key), executor); FUTURES.put(key, completableFuture); return null; } finally { // unlock LOCK.unlock(); } }
/** * Delegate for actually executing the given task with the chosen executor. * @param task the task to execute * @param executor the chosen executor * @param returnType the declared return type (potentially a {@link Future} variant) * @return the execution result (potentially a corresponding {@link Future} handle) */ @Nullable protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) { if (CompletableFuture.class.isAssignableFrom(returnType)) { return CompletableFuture.supplyAsync(() -> { try { return task.call(); } catch (Throwable ex) { throw new CompletionException(ex); } }, executor); } else if (ListenableFuture.class.isAssignableFrom(returnType)) { return ((AsyncListenableTaskExecutor) executor).submitListenable(task); } else if (Future.class.isAssignableFrom(returnType)) { return executor.submit(task); } else { executor.submit(task); return null; } }
@Override default CompletableFuture<V> get(@NonNull K key, @NonNull Function<? super K, ? extends V> mappingFunction) { requireNonNull(mappingFunction); return get(key, (k1, executor) -> CompletableFuture.supplyAsync( () -> mappingFunction.apply(key), executor)); }
@Override public <T> CompletionStage<T> method(final String name, final Entity<?> entity, final GenericType<T> responseType) { final ExecutorService executorService = getExecutorService(); return executorService == null ? CompletableFuture.supplyAsync(() -> getSyncInvoker().method(name, entity, responseType)) : CompletableFuture.supplyAsync(() -> getSyncInvoker().method(name, entity, responseType), executorService); } }
@Override public Object get(DataFetchingEnvironment environment) { CompletableFuture<User> userPromise = CompletableFuture.supplyAsync( () -> { return fetchUserFromDatabase(environment.getArgument("userId")); }); return userPromise; } };
public CompletableFuture<List<Project>> getProjectsForCompanies(List<UUID> companyIds) { return CompletableFuture.supplyAsync(() -> projects.values().stream() .filter(project -> companyIds.contains(project.getCompanyId())) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList))); }
private void succinctAsyncDataFetcher() { //::FigureF DataFetcher userDataFetcher = environment -> CompletableFuture.supplyAsync( () -> fetchUserFromDatabase(environment.getArgument("userId"))); //::/FigureF }
@Override public Object get(DataFetchingEnvironment environment) { // // Don't DO THIS! // return CompletableFuture.supplyAsync(() -> { String argId = environment.getArgument("id"); DataLoader<String, Object> characterLoader = environment.getDataLoader("characterLoader"); return characterLoader.load(argId); }); } };
@Override public CompletionStage<List<Object>> load(List<String> keys, BatchLoaderEnvironment loaderContext) { // // we can have an overall context object SecurityContext securityCtx = loaderContext.getContext(); // // and we can have a per key set of context objects Map<Object, Object> keysToSourceObjects = loaderContext.getKeyContexts(); return CompletableFuture.supplyAsync(() -> getTheseCharacters(securityCtx.getToken(), keys, keysToSourceObjects)); } };