Example usage for java.util.function Consumer accept

List of usage examples for java.util.function Consumer accept

Introduction

In this page you can find the example usage for java.util.function Consumer accept.

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:io.github.azige.moebooruviewer.io.MoebooruRepository.java

/**
 * Load a image asynchronously.//ww w.j  a  va2s  . c  o  m
 * The callback will be invoked with loaded image when succeeded
 * or null when failed.
 *
 * @param url
 * @param localFile
 * @param useCache
 * @param callback
 */
public void loadImageAsync(String url, File localFile, boolean useCache, Consumer<Image> callback) {
    loadImageAsync(url, localFile, useCache, new DownloadCallbackAdapter() {
        @Override
        public void onComplete(File file) {
            callback.accept(Utils.loadImage(file));
        }

        @Override
        public void onFail(Exception ex) {
            callback.accept(null);
        }
    });
}

From source file:org.jboss.as.test.integration.domain.events.JmxControlledStateNotificationsTestCase.java

private void readAndCheckFile(File file, Consumer<List<String>> consumer) throws IOException {
    Assert.assertTrue("File not found " + file.getAbsolutePath(), file.exists());
    consumer.accept(Files.readAllLines(file.toPath(), StandardCharsets.UTF_8));
}

From source file:com.byteatebit.nbserver.task.ReadDelimitedMessageTask.java

protected void invokeExceptionHandler(SelectionKey selectionKey, Consumer<Exception> exceptionHandler,
        Exception exception) {/*  www  .j  a  v a 2  s.  c  o m*/
    selectionKey.interestOps(selectionKey.interestOps() & ~SelectionKey.OP_READ);
    try {
        exceptionHandler.accept(exception);
    } catch (Exception e) {
        LOG.error("Read exception handler failed", e);
    }
}

From source file:com.diversityarrays.kdxplore.curate.SuppressionHandler.java

public void registerRejectedSamples(List<EditedSampleInfo> infoList, String reason) {
    curationData.registerRejectedSampleInfo(infoList, reason);
    for (Consumer<List<KdxSample>> repaintConsumer : repaintConsumers) {
        repaintConsumer.accept(new ArrayList<>());
    }/*  w  w  w. ja va  2s . com*/
}

From source file:com.diversityarrays.kdxplore.curate.SuppressionHandler.java

public void registerAcceptedSamples(List<EditedSampleInfo> infoList) {
    curationData.registerAcceptedSampleInfo(infoList); // ???? been through here
    for (Consumer<List<KdxSample>> repaintConsumer : repaintConsumers) {
        repaintConsumer.accept(new ArrayList<>());
    }/*from   w  w w  .j  a va  2 s .  c  om*/
}

From source file:spring.travel.site.services.HttpClient.java

private <T> CompletableFuture<T> execute(Supplier<Request> requestSupplier, Consumer<Request> requestConsumer,
        ResponseMapper<T> responseMapper) {
    CompletableFuture<T> future = new CompletableFuture<>();
    try {/*ww w.  j a  v  a 2  s . co  m*/
        Request request = requestSupplier.get();
        requestConsumer.accept(request);
        asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<T>() {
            @Override
            public T onCompleted(Response response) throws Exception {
                T t = responseMapper.map(response);
                future.complete(t);
                return t;
            }

            @Override
            public void onThrowable(Throwable t) {
                future.completeExceptionally(t);
            }
        });
    } catch (Exception e) {
        future.completeExceptionally(e);
    }
    return future;
}

From source file:io.tilt.minka.business.impl.TransportlessLeaderShardContainer.java

@Override
public void setNewLeader(final NetworkShardID newLeader) {
    Validate.notNull(newLeader, "Cannot set a Null leader !");
    try {//  w  ww. j  a  v  a  2s.  c  om
        boolean firstLeader = lastLeaderShardId == null;
        if (!firstLeader && lastLeaderShardId.equals(newLeader)) {
            logger.info("{}: ({}) same Leader {} reelected, skipping observer notification",
                    getClass().getSimpleName(), myShardId, this.leaderShardId.getStringID());
            previousLeaders.add(leaderShardId);
        } else {
            logger.info("{}: ({}) Updating new Leader elected: {}", getClass().getSimpleName(), myShardId,
                    newLeader);
            if (!firstLeader) {
                previousLeaders.add(leaderShardId);
            }
            leaderShardId = newLeader;
            for (Consumer<NetworkShardID> o : this.observers) {
                logger.info("{}: ({}) Notifying observer: {}", getClass().getSimpleName(), myShardId,
                        o.getClass().getSimpleName());
                o.accept(this.leaderShardId);
            }
            lastLeaderShardId = newLeader;
        }
    } catch (Exception e) {
        logger.error("{}: ({}) LeaderShardContainer: unexpected error", getClass().getSimpleName(), myShardId,
                e);
    }
}

From source file:com.vsct.dt.hesperides.indexation.ElasticSearchIndexationExecutor.java

public <T> Future<Void> index(final ElasticSearchIndexationCommand task) {
    return singleThreadPool.submit(new Callable<Void>() {
        @Override/*  w  ww .ja  v  a  2s  .  c o m*/
        public Void call() {
            withMaxRetry(nRetries, waitBeforeRetryMs, t -> t.index(elasticSearchClient));
            return null;
        }

        private void withMaxRetry(final int maxRetry, final int wait,
                final Consumer<ElasticSearchIndexationCommand> consumer) {
            int count = 1;
            for (;;) {
                try {
                    consumer.accept(task);
                    return;
                } catch (Exception e) {
                    if (count < maxRetry) {
                        LOGGER.warn("Indexation task failed. Retry in {} milliseconds", wait);
                        try {
                            Thread.sleep(wait);
                        } catch (final InterruptedException ie) {
                            ie.printStackTrace();
                        }
                        count++;
                    } else {
                        LOGGER.error(
                                "Indexation task failed after {} attempts. Index might be broken. Reason: {} {}",
                                nRetries, e, e.getMessage());
                        return;
                    }
                }
            }
        }

    });
}

From source file:biz.fstechnology.micro.common.jms.JmsServiceConnection.java

/**
 * @see biz.fstechnology.micro.common.DefaultServiceConnection#callAsync(biz.fstechnology.micro.common.Request,
 * java.util.function.Consumer)//  w  w w  . j  a va2 s .  com
 */
@Override
public <T, U> void callAsync(Request<T> request, Consumer<Result<U>> callback) {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Result<U>> rawResponse = executor.submit(() -> call(request));
    executor.submit(() -> {
        try {
            callback.accept(rawResponse.get());
        } catch (Exception e) {
            e.printStackTrace();
            Result<U> result = new Result<>(e);
            callback.accept(result);
        }
    });
    executor.shutdown();
}

From source file:org.keycloak.testsuite.util.SamlClientBuilder.java

/**
 * Execute the current steps and pass the final response to the {@code resultConsumer} for processing.
 * @param resultConsumer This function is given the final response
 * @return Client that executed the steps
 *//*from   ww  w . j  a v a2  s .  com*/
public SamlClient execute(Consumer<CloseableHttpResponse> resultConsumer) {
    final SamlClient samlClient = new SamlClient();
    samlClient.executeAndTransform(r -> {
        resultConsumer.accept(r);
        return null;
    }, steps);
    return samlClient;
}