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.netflix.genie.core.services.impl.JobStateServiceImpl.java

private void handle(final String jobId, final Supplier<Void> supplier) {
    JobInfo jobInfo = jobs.get(jobId);//from w  ww.  j ava 2 s  .  c o  m
    if (jobInfo != null) {
        synchronized (jobInfo) {
            jobInfo = jobs.get(jobId);
            if (jobInfo != null) {
                supplier.get();
            }
        }
    }
}

From source file:nu.yona.server.messaging.service.MessageService.java

@Transactional
public void broadcastMessageToBuddies(UserAnonymizedDto userAnonymized, Supplier<Message> messageSupplier) {
    buddyService.getBuddyDestinations(userAnonymized)
            .forEach(destination -> sendMessageAndFlushToDatabase(messageSupplier.get(), destination));
}

From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCacheTest.java

@SuppressWarnings("unchecked")
private Supplier<String> getMockRandomGenerator() {
    Supplier<String> generator = mock(Supplier.class);

    when(generator.get()).thenReturn("RANDOM");

    return generator;
}

From source file:org.thevortex.lighting.jinks.client.WinkClient.java

/**
 * Runs an authentication request./*from  w  ww .  java2s .  co m*/
 *
 * @param authRequest the request
 * @throws IOException dang
 */
protected void handleAuthRequest(Supplier<ObjectNode> authRequest) throws IOException {
    String requestBody = payloadMapper.writeValueAsString(authRequest.get());

    // just pop off the POST request, nothing fancy
    HttpPost post = new HttpPost(OAUTH);
    post.setEntity(new StringEntity(requestBody));
    post.setHeader("Content-Type", "application/json");
    post.setHeader("User-Agent", appName);
    logger.info("Starting authentication...");
    try (CloseableHttpResponse response = getClient().execute(winkHost, post)) {
        StatusLine status = response.getStatusLine();
        int statusCode = status.getStatusCode();
        switch (statusCode) {
        case 200:
        case 201: {
            String body = EntityUtils.toString(response.getEntity());
            ObjectNode auth = payloadMapper.readValue(body, ObjectNode.class);
            sessionToken = auth.path("data").get("access_token").asText();
            logger.debug("SessionToken: {}", sessionToken);
            renewToken = auth.path("data").get("refresh_token").asText();
            logger.debug("RenewToken: {}", renewToken);
            logger.info("Authenticated!");
            return;
        }
        case 401:
            throw new AuthenticationException("Unauthorized");
        case 403:
            throw new AuthenticationException("Forbidden");
        default:
            handleErrorCodes(status);
        }
    }
}

From source file:com.diffplug.gradle.p2.P2Model.java

/**
 * There are places where we add the local bundle pool
 * to act as an artifact cache.  But sometimes, that cache
 * doesn't exist yet.  To make sure we don't get an error
 * just because a cache doesn't exist, we create the bundle
 * pool if we need it//from   w  ww  . j a v  a2 s .c om
 * 
 * - Copy the current model.
 * - Remove the bundle pool if it doesn't exist.
 * - Call the supplier.
 * - If removed any repos, put them back.
 * - Return the result.
 */
private <T> T performWithoutMissingBundlePool(Supplier<T> supplier) {
    createBundlePoolIfNecessary();
    return supplier.get();
}

From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.OrcaRunner.java

private void monitor(Supplier<Pipeline> getPipeline) {
    String status;/*from   w  ww.j  av a2  s.  co  m*/
    Pipeline pipeline;
    Set<String> loggedTasks = new HashSet<>();
    try {
        pipeline = getPipeline.get();
        status = pipeline.getStatus();

        while (status.equalsIgnoreCase("running") || status.equalsIgnoreCase("not_started")) {
            logPipelineOutput(pipeline, loggedTasks);
            DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
            pipeline = getPipeline.get();
            status = pipeline.getStatus();
        }
    } catch (RetrofitError e) {
        throw new HalException(
                new ProblemBuilder(Problem.Severity.FATAL, "Failed to monitor task: " + e.getMessage())
                        .build());
    }

    logPipelineOutput(pipeline, loggedTasks);

    if (status.equalsIgnoreCase("terminal")) {
        Problem problem = findExecutionError(pipeline);
        throw new HalException(problem);
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.OrcaRunner.java

private void monitor(Supplier<Pipeline> getPipeline, Orca orca) {
    String status;//from   ww  w . java 2s .co m
    Pipeline pipeline;
    Set<String> loggedTasks = new HashSet<>();
    try {
        pipeline = getPipeline.get();
        status = pipeline.getStatus();

        while (status.equalsIgnoreCase("running") || status.equalsIgnoreCase("not_started")) {
            logPipelineOutput(pipeline, loggedTasks);
            try {
                Thread.sleep(TimeUnit.SECONDS.toMillis(5));
            } catch (InterruptedException ignored) {
            }
            pipeline = getPipeline.get();
            status = pipeline.getStatus();
        }
    } catch (RetrofitError e) {
        throw new HalException(
                new ProblemBuilder(Problem.Severity.FATAL, "Failed to monitor task: " + e.getMessage())
                        .build());
    }

    logPipelineOutput(pipeline, loggedTasks);

    if (status.equalsIgnoreCase("terminal")) {
        Problem problem = findExecutionError(pipeline);
        throw new HalException(problem);
    }
}

From source file:com.github.tddts.jet.service.impl.LoginServiceImpl.java

@Override
public void processLogin(Supplier<Optional<Pair<String, String>>> credentialsSupplier,
        Consumer<URI> loginUriConsumer) {
    AuthorizationType authType = userBean.getAuthorizationType();

    server.start();/*  w w  w .ja va2s . c o  m*/

    if (authType.isImplicit()) {
        loginUriConsumer.accept(authService.getLoginPageURI());
    }

    if (authType.isDev()) {
        Optional<Pair<String, String>> credentialsPair = credentialsSupplier.get();

        credentialsPair.ifPresent(creds -> {
            userBean.setClientId(creds.getKey());
            userBean.setSercretKey(creds.getValue());
            loginUriConsumer.accept(authService.getLoginPageURI(userBean.getClientId()));
        });

    }
}

From source file:com.controller.schedule.ScheduleSocialPostActionsServlet.java

private List<String> validateJsonData(String jsonDataString, String errorMsgSuffix,
        Supplier<Set<String>> requiredKeysBuilder) {
    List<String> errorMsgs = new ArrayList<>();

    Map<String, Object> jsonDataMap = AppConstants.GSON.fromJson(jsonDataString, Map.class);

    Set<String> requiredKeys = requiredKeysBuilder.get();

    Set<String> keySet = jsonDataMap.keySet();
    requiredKeys.stream().filter((key) -> (!keySet.contains(key))).forEach((key) -> {
        errorMsgs.add(key + errorMsgSuffix);
    });//from   www  .j a  v  a  2s  . c  o  m

    return errorMsgs;
}

From source file:com.github.erchu.beancp.MapperImpl.java

private <D> D constructObjectUsingDestinationObjectBuilder(final Supplier<D> destinationObjectBuilder,
        final Class<D> destinationClass) throws MappingException {
    notNull(destinationObjectBuilder, "destinationObjectBuilder");
    notNull(destinationClass, "destinationClass");

    D destination;/*from ww w .  j  a va  2s. c o m*/

    try {
        destination = destinationObjectBuilder.get();
    } catch (Exception ex) {
        throw new MappingException(String.format(
                "Failed to create destination object class %s " + "using constructDestinationObjectUsing.",
                destinationClass));
    }

    if (destinationClass.isAssignableFrom(destination.getClass()) == false) {
        throw new MappingException(String.format(
                "Destination object class %s returned "
                        + "by constructDestinationObjectUsing cannot be assigned to expected " + "class %s.",
                destination.getClass(), destinationClass));
    }

    return destination;
}