Example usage for java.util.concurrent CompletableFuture completedFuture

List of usage examples for java.util.concurrent CompletableFuture completedFuture

Introduction

In this page you can find the example usage for java.util.concurrent CompletableFuture completedFuture.

Prototype

public static <U> CompletableFuture<U> completedFuture(U value) 

Source Link

Document

Returns a new CompletableFuture that is already completed with the given value.

Usage

From source file:io.pravega.controller.mocks.EventStreamWriterMock.java

@Override
public CompletableFuture<Void> writeEvent(T event) {
    eventList.add(event);
    return CompletableFuture.completedFuture(null);
}

From source file:io.pravega.controller.mocks.EventStreamWriterMock.java

@Override
public CompletableFuture<Void> writeEvent(String routingKey, T event) {
    eventList.add(event);
    return CompletableFuture.completedFuture(null);
}

From source file:com.teradata.benchto.driver.listeners.LoggingBenchmarkExecutionListener.java

@Override
public Future<?> benchmarkStarted(Benchmark benchmark) {
    LOG.info("Executing benchmark: {}", benchmark.getName());

    return CompletableFuture.completedFuture("");
}

From source file:com.teradata.benchto.driver.listeners.LoggingBenchmarkExecutionListener.java

@Override
public Future<?> benchmarkFinished(BenchmarkExecutionResult result) {
    LOG.info("Finished benchmark: {}", result.getBenchmark().getName());

    return CompletableFuture.completedFuture("");
}

From source file:am.ik.categolj3.api.jest.JestIndexer.java

@Async
public CompletableFuture<Void> reindex() {
    log.info("re-indexing ...");
    List<Entry> entries = gitStore.loadEntries();
    Bulk.Builder bulkBuilder = new Bulk.Builder();
    for (Entry entry : entries) {
        Index index = new Index.Builder(entry).refresh(true).index(Entry.INDEX_NAME).type(Entry.DOC_TYPE)
                .build();//  w w w .j ava2s .co m
        bulkBuilder.addAction(index);
    }
    try {
        jestClient.execute(bulkBuilder.build());
        log.info("re-indexed!");
        return CompletableFuture.completedFuture(null);
    } catch (Exception e) {
        CompletableFuture<Void> f = new CompletableFuture<>();
        f.completeExceptionally(e);
        return f;
    }
}

From source file:com.teradata.benchto.driver.listeners.LoggingBenchmarkExecutionListener.java

@Override
public Future<?> executionStarted(QueryExecution execution) {
    LOG.info("Query started: {} ({}/{})", execution.getQueryName(), execution.getRun(),
            execution.getBenchmark().getRuns());

    return CompletableFuture.completedFuture("");
}

From source file:com.spotify.styx.api.Middlewares.java

public static Middleware<AsyncHandler<? extends Response<?>>, AsyncHandler<? extends Response<ByteString>>> clientValidator(
        Supplier<Optional<List<String>>> supplier) {
    return innerHandler -> requestContext -> {
        if (requestContext.request().header("User-Agent")
                .map(header -> supplier.get().orElse(ImmutableList.of()).contains(header)).orElse(false)) {
            // TODO: fire some stats
            return CompletableFuture.completedFuture(Response.forStatus(
                    Status.NOT_ACCEPTABLE.withReasonPhrase("blacklisted client version, please upgrade")));
        } else {/*from  ww  w. j a  va 2  s  .  c  o m*/
            // noinspection unchecked
            return (CompletionStage<Response<ByteString>>) innerHandler.invoke(requestContext);
        }
    };
}

From source file:com.ikanow.aleph2.core.shared.utils.JarCacheUtils.java

/** Moves a shared JAR into a local spot (if required)
 * @param library_bean//w  w  w .ja  va  2  s. c o  m
 * @param fs
 * @return either a basic message bean containing an error, or the fully qualified path of the cached JAR
 */
public static <M> CompletableFuture<Validation<BasicMessageBean, String>> getCachedJar(
        final String local_cached_jar_dir, final SharedLibraryBean library_bean, final IStorageService fs,
        final String handler_for_errors, final M msg_for_errors) {
    try {
        final FileContext dfs = fs.getUnderlyingPlatformDriver(FileContext.class, Optional.empty()).get();
        final FileContext lfs = fs.getUnderlyingPlatformDriver(FileContext.class, IStorageService.LOCAL_FS)
                .get();

        final Path cached_jar_file = lfs
                .makeQualified(new Path(local_cached_jar_dir + "/" + buildCachedJarName(library_bean)));
        final Path original_jar_file = dfs.makeQualified(new Path(library_bean.path_name()));

        final FileStatus file_status = dfs.getFileStatus(original_jar_file); // (this will exception out if it doesn't exist, as it should)

        try {
            final FileStatus local_file_status = lfs.getFileStatus(cached_jar_file); // (this will exception in to case 2 if it doesn't exist)

            // if the local version exists then overwrite it

            if (file_status.getModificationTime() > local_file_status.getModificationTime()) {
                // (it gets kinda complicated here so just invalidate the entire classloader cache..)
                // TODO (ALEPH-12): add a coverage test for this
                ClassloaderUtils.clearCache();

                lfs.util().copy(original_jar_file, cached_jar_file, false, true);
            }
        } catch (FileNotFoundException f) {

            // 2) if the local version doesn't exist then just copy the distributed file across
            // (note: don't need to do anything with the classloader cache here since the file doesn't exist so can't have a cache key)

            lfs.util().copy(original_jar_file, cached_jar_file);
        }
        return CompletableFuture.completedFuture(Validation.success(cached_jar_file.toString()));

    } catch (Throwable e) {
        return CompletableFuture.completedFuture(
                Validation.fail(SharedErrorUtils.buildErrorMessage(handler_for_errors, msg_for_errors,
                        SharedErrorUtils.getLongForm(SharedErrorUtils.SHARED_LIBRARY_NAME_NOT_FOUND, e,
                                library_bean.path_name()))));
    }
}

From source file:org.trustedanalytics.routermetrics.GatheringJobTests.java

private CompletableFuture<ResponseEntity<GorouterMetrics>> gorouterAnswer(double value)
        throws ExecutionException, InterruptedException {

    GorouterMetrics gorouterMetrics = new GorouterMetrics();
    gorouterMetrics.setRequestPerSec(value);
    ResponseEntity<GorouterMetrics> responseEntity = new ResponseEntity<>(gorouterMetrics, HttpStatus.OK);

    return CompletableFuture.completedFuture(responseEntity);
}

From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java

@Before
public void setUp() throws Exception {

    final HermesResponse response = HermesResponseBuilder.hermesResponse().withHttpStatus(201).build();

    when(hermesSender.send(any(URI.class), any(HermesMessage.class)))
            .thenReturn(CompletableFuture.completedFuture(response));

    binder = new HermesClientBinder(HermesClientBuilder.hermesClient(hermesSender).build());
    binder.setApplicationContext(new GenericApplicationContext());
}