Example usage for java.util.function Supplier get

List of usage examples for java.util.function Supplier get

Introduction

In this page you can find the example usage for java.util.function Supplier get.

Prototype

T get();

Source Link

Document

Gets a result.

Usage

From source file:com.samsung.sjs.theorysolver.TheorySolver.java

private static <T> T timed(Supplier<T> f, String msg) {
    if (NOISY) {/*from www  . j  ava2s  .c o m*/
        System.out.print(msg + "... ");
        System.out.flush();
        long start = System.currentTimeMillis();
        T result = f.get();
        long duration = System.currentTimeMillis() - start;
        System.out.println(duration + "ms");
        return result;
    } else {
        return f.get();
    }
}

From source file:org.graylog2.indexer.cluster.jest.JestUtils.java

private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage,
        JsonObject rootCause, List<String> reasons) {
    final Integer line = asInteger(rootCause.get("line"));
    final Integer column = asInteger(rootCause.get("col"));
    final String index = asString(rootCause.get("index"));

    return new QueryParsingException(errorMessage.get(), line, column, index, reasons);
}

From source file:com.yahoo.elide.extensions.JsonApiPatch.java

/**
 * Merge response documents to create final response.
 *//*from   w w  w. ja  v a 2  s  . c  o m*/
private static JsonNode mergeResponse(List<Supplier<Pair<Integer, JsonNode>>> results) {
    ArrayNode list = JsonNodeFactory.instance.arrayNode();
    for (Supplier<Pair<Integer, JsonNode>> result : results) {
        JsonNode node = result.get().getRight();
        if (node == null || node instanceof NullNode) {
            node = JsonNodeFactory.instance.objectNode().set("data", null);
        }
        list.add(node);
    }
    return list;
}

From source file:co.runrightfast.vertx.core.application.RunRightFastVertxApplicationLauncher.java

private static void runApp(final Supplier<RunRightFastVertxApplication> app) {
    final RunRightFastVertxApplicationLauncher service = RunRightFastVertxApplicationLauncher.builder()
            .app(app.get()).build();
    log.logp(INFO, CLASS_NAME, "runApp", "starting");
    service.startAsync();//from ww  w .jav a  2  s.  c om
    service.awaitRunning();
    log.logp(INFO, CLASS_NAME, "runApp", "running");
    service.awaitTerminated();
    log.logp(INFO, CLASS_NAME, "runApp", "terminated");
}

From source file:ch.ivyteam.ivy.maven.engine.EngineControl.java

private static long waitFor(Supplier<Boolean> condition, long duration, TimeUnit unit) throws Exception {
    StopWatch watch = new StopWatch();
    watch.start();/*from  w w w  . java 2 s. c  om*/
    long timeout = unit.toMillis(duration);

    while (!condition.get()) {
        Thread.sleep(1_000);
        if (watch.getTime() > timeout) {
            throw new TimeoutException("Condition not reached in " + duration + " " + unit);
        }
    }

    return watch.getTime();
}

From source file:rdfconnection.RDFConnectionRemote.java

/** Convert HTTP status codes to exceptions */
static <X> X exec(Supplier<X> action) {
    try {/*  w w  w  .  j a  v a  2  s .c om*/
        return action.get();
    } catch (HttpException ex) {
        handleHttpException(ex, true);
        return null;
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.google.GoogleProviderUtils.java

private static void waitOnOperation(Supplier<Operation> operationSupplier) {
    Operation operation = operationSupplier.get();
    while (!operation.getStatus().equals("DONE")) {
        if (operation.getError() != null) {
            throw new HalException(FATAL, String.join("\n", operation.getError().getErrors().stream()
                    .map(e -> e.getCode() + ": " + e.getMessage()).collect(Collectors.toList())));
        }// w  w w.j  av  a  2s  .co  m
        operation = operationSupplier.get();
        DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1));
    }
}

From source file:onl.area51.filesystem.http.client.HttpUtils.java

public static void retrieve(char[] path, Function<char[], String> remoteUri, Supplier<FileSystemIO> delegate,
        Supplier<String> userAgent) throws IOException {
    if (path == null || path.length == 0) {
        throw new FileNotFoundException("/");
    }/*from   w ww .j a  v a2s.  com*/

    String uri = remoteUri.apply(path);
    if (uri != null) {

        LOG.log(Level.FINE, () -> "Retrieving " + uri);

        HttpGet get = new HttpGet(uri);
        get.setHeader(USER_AGENT, userAgent.get());

        try (CloseableHttpClient client = HttpClients.createDefault()) {
            try (CloseableHttpResponse response = client.execute(get)) {

                int returnCode = response.getStatusLine().getStatusCode();
                LOG.log(Level.FINE,
                        () -> "ReturnCode " + returnCode + ": " + response.getStatusLine().getReasonPhrase());

                switch (returnCode) {
                case 200:
                case 304:
                    FileSystemUtils.copyFromRemote(() -> response.getEntity().getContent(), delegate.get(),
                            path);
                    return;

                default:
                }
            }
        }
    }

    throw new FileNotFoundException(String.valueOf(path));
}

From source file:org.graylog2.indexer.cluster.jest.JestUtils.java

public static <T extends JestResult> T execute(JestClient client, RequestConfig requestConfig,
        Action<T> request, Supplier<String> errorMessage) {
    final T result;
    try {/*from   ww w .java2  s.c  o m*/
        if (client instanceof JestHttpClient) {
            result = ((JestHttpClient) client).execute(request, requestConfig);
        } else {
            result = client.execute(request);
        }
    } catch (IOException e) {
        throw new ElasticsearchException(errorMessage.get(), e);
    }

    if (result.isSucceeded()) {
        return result;
    } else {
        throw specificException(errorMessage, result.getJsonObject());
    }
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java

static void logMalformedManifest(Supplier<String> contextMessage, KubernetesManifest manifest) {
    if (manifest == null) {
        log.warn("{}: manifest may not be null", contextMessage.get());
        return;//from w  ww  .  ja v a2 s. c om
    }

    if (manifest.getKind() == null) {
        log.warn("{}: manifest kind may not be null, {}", contextMessage.get(), manifest);
    }

    if (StringUtils.isEmpty(manifest.getName())) {
        log.warn("{}: manifest name may not be null, {}", contextMessage.get(), manifest);
    }

    if (StringUtils.isEmpty(manifest.getNamespace()) && manifest.getKind().isNamespaced()) {
        log.warn("{}: manifest namespace may not be null, {}", contextMessage.get(), manifest);
    }
}