Example usage for com.google.common.util.concurrent ListeningExecutorService submit

List of usage examples for com.google.common.util.concurrent ListeningExecutorService submit

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ListeningExecutorService submit.

Prototype

@Override
ListenableFuture<?> submit(Runnable task);

Source Link

Usage

From source file:com.google.gerrit.server.notedb.ChangeRebuilder.java

public final ListenableFuture<Result> rebuildAsync(final Change.Id id, ListeningExecutorService executor) {
    return executor.submit(new Callable<Result>() {
        @Override//  ww  w  . j  a va  2 s. c  o  m
        public Result call() throws Exception {
            try (ReviewDb db = schemaFactory.open()) {
                return rebuild(db, id);
            }
        }
    });
}

From source file:com.google.gerrit.server.notedb.rebuild.ChangeRebuilder.java

public final ListenableFuture<Result> rebuildAsync(Change.Id id, ListeningExecutorService executor) {
    return executor.submit(() -> {
        try (ReviewDb db = schemaFactory.open()) {
            return rebuild(db, id);
        }//from www.  j  a  v a  2 s .c o m
    });
}

From source file:com.google.idea.blaze.base.vcs.git.GitBlazeVcsHandler.java

@Override
public ListenableFuture<WorkingSet> getWorkingSet(Project project, BlazeContext context,
        WorkspaceRoot workspaceRoot, ListeningExecutorService executor) {
    return executor.submit(() -> {
        String upstreamSha = getUpstreamSha(workspaceRoot, false);
        if (upstreamSha == null) {
            return null;
        }/*from  w ww  .  ja v  a  2 s .c  o m*/
        return GitWorkingSetProvider.calculateWorkingSet(workspaceRoot, upstreamSha);
    });
}

From source file:com.yahoo.yqlplus.engine.internal.java.sequences.Sequences.java

public static <ROW, SEQUENCE extends Iterable<ROW>, SET> ListenableFuture<List<ROW>> invokeBatchSet(
        final ListeningExecutorService workExecutor, final Function<List<SET>, SEQUENCE> source,
        final Tracer tracer, final Timeout timeout, final TimeoutHandler handler, final List<ROW>... inputs)
        throws Exception {
    final List<ListenableFuture<SEQUENCE>> results = Lists.newArrayList();
    for (List<ROW> input : inputs) {
        for (int i = 0; i < input.size(); i++) {
            Record record = (Record) input.get(i);
            List methodArgs = Lists.newArrayList();
            Iterable<String> fieldNames = record.getFieldNames();
            for (String fieldName : fieldNames) {
                methodArgs.add(record.get(fieldName));
            }//from  ww  w. j ava2  s  . c  o  m
            results.add(workExecutor.submit(createJob(tracer, source, methodArgs)));
        }
    }
    final ListenableFuture<List<SEQUENCE>> gather = Futures.allAsList(results);
    return handler.withTimeout(gatherResults(workExecutor, gather, 1), timeout.verify(),
            timeout.getTickUnits());
}

From source file:org.apache.beam.sdk.util.GcsUtil.java

private static void executeBatches(List<BatchRequest> batches) throws IOException {
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(
            MoreExecutors.getExitingExecutorService(new ThreadPoolExecutor(MAX_CONCURRENT_BATCHES,
                    MAX_CONCURRENT_BATCHES, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>())));

    List<ListenableFuture<Void>> futures = new LinkedList<>();
    for (final BatchRequest batch : batches) {
        futures.add(executor.submit(new Callable<Void>() {
            public Void call() throws IOException {
                batch.execute();// w w  w .j a v a 2s  . c om
                return null;
            }
        }));
    }

    try {
        Futures.allAsList(futures).get();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Interrupted while executing batch GCS request", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof FileNotFoundException) {
            throw (FileNotFoundException) e.getCause();
        }
        throw new IOException("Error executing batch GCS request", e);
    } finally {
        executor.shutdown();
    }
}

From source file:org.apache.jclouds.profitbricks.rest.compute.concurrent.ProvisioningManager.java

public Object provision(ProvisioningJob job) {
    if (terminated.get()) {
        logger.warn("Job(%s) submitted but the provisioning manager is already closed", job);
        return null;
    }/*from w  ww . ja va  2s.co m*/

    logger.debug("Job(%s) submitted to group '%s'", job, job.getGroup());
    ListeningExecutorService workerGroup = getWorkerGroup(job.getGroup());
    return getUnchecked(workerGroup.submit(job));
}

From source file:org.d4rxh4wx.thread.executor.ListeningThreadPoolTaskExecutor.java

@Override
public Future<?> submit(Runnable task) {
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(getThreadPoolExecutor());

    try {// www  . ja  va 2s  .  c om
        return executor.submit(task);
    } catch (RejectedExecutionException ex) {
        throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
    }
}

From source file:org.d4rxh4wx.thread.executor.ListeningThreadPoolTaskExecutor.java

@Override
public <T> Future<T> submit(Callable<T> task) {
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(getThreadPoolExecutor());

    try {/*w ww .j a  v a 2 s. c o m*/
        return executor.submit(task);
    } catch (RejectedExecutionException ex) {
        throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
    }
}

From source file:com.stegosaurus.genetic.ParallelIndividual.java

/**
 * Start to run simulate and calculateFitness for this individual, on
 * another thread./*from  w ww. j ava 2s .c om*/
 * The result may be later retreived via the calculateFitness() function.
 * @param executorService the service to use to start up the calculation.
 */
public synchronized void startFitnessCalculation(ListeningExecutorService executorService) {
    fitnessFuture = executorService.submit(new Callable<Double>() {
        public Double call() {
            decorated.simulate();
            return decorated.calculateFitness();
        }
    });
}

From source file:org.openhab.binding.flicbutton.handler.FlicDaemonBridgeHandler.java

private void listenToFlicDaemonAsync() throws UnknownHostException {
    FlicDaemonBridgeEventListener flicDaemonEventListener = new FlicDaemonBridgeEventListener(this);
    FlicDaemonClientRunner flicClientService = new FlicDaemonClientRunner(flicDaemonEventListener,
            cfg.getHostname(), cfg.getPort());

    ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(scheduler);
    flicClientFuture = listeningExecutor.submit(flicClientService);
}