List of usage examples for com.google.common.util.concurrent ListeningExecutorService execute
void execute(Runnable command);
From source file:com.facebook.buck.rules.modern.builders.IsolatedExecutionStrategy.java
@Override public void build(ListeningExecutorService service, BuildRule rule, BuildExecutorRunner executorRunner) { Preconditions.checkState(rule instanceof ModernBuildRule); service.execute(() -> executorRunner .runWithExecutor((executionContext, buildRuleBuildContext, buildableContext, stepRunner) -> { executeRule(rule, executionContext, buildRuleBuildContext, buildableContext); }));//from ww w . j a va 2 s . c o m }
From source file:com.facebook.buck.rules.CachingBuildRuleBuilder.java
private ListenableFuture<Optional<BuildResult>> buildLocally(final CacheResult cacheResult, final ListeningExecutorService service) throws StepFailedException, InterruptedException { if (SupportsPipelining.isSupported(rule)) { return pipelinesRunner.runPipelineStartingAt((SupportsPipelining<?>) rule, service); } else {//from www . j a v a2 s .co m BuildRuleSteps<RulePipelineState> buildRuleSteps = new BuildRuleSteps<>(cacheResult, null); service.execute(buildRuleSteps); return buildRuleSteps.getFuture(); } }
From source file:org.apache.cassandra.repair.RepairSession.java
/** * Start RepairJob on given ColumnFamilies. * * This first validates if all replica are available, and if they are, * creates RepairJobs and submit to run on given executor. * * @param executor Executor to run validation *///w ww. j a v a 2 s . c om public void start(ListeningExecutorService executor) { String message; if (terminated) return; logger.info(String.format("[repair #%s] new session: will sync %s on range %s for %s.%s", getId(), repairedNodes(), range, keyspace, Arrays.toString(cfnames))); Tracing.traceRepair("Syncing range {}", range); SystemDistributedKeyspace.startRepairs(getId(), parentRepairSession, keyspace, cfnames, range, endpoints); if (endpoints.isEmpty()) { logger.info("[repair #{}] {}", getId(), message = String.format("No neighbors to repair with on range %s: session completed", range)); Tracing.traceRepair(message); set(new RepairSessionResult(id, keyspace, range, Lists.<RepairResult>newArrayList())); SystemDistributedKeyspace.failRepairs(getId(), keyspace, cfnames, new RuntimeException(message)); return; } // Checking all nodes are live for (InetAddress endpoint : endpoints) { if (!FailureDetector.instance.isAlive(endpoint)) { message = String.format("Cannot proceed on repair because a neighbor (%s) is dead: session failed", endpoint); logger.error("[repair #{}] {}", getId(), message); Exception e = new IOException(message); setException(e); SystemDistributedKeyspace.failRepairs(getId(), keyspace, cfnames, e); return; } } // Create and submit RepairJob for each ColumnFamily List<ListenableFuture<RepairResult>> jobs = new ArrayList<>(cfnames.length); for (String cfname : cfnames) { RepairJob job = new RepairJob(this, cfname, parallelismDegree, repairedAt, taskExecutor); executor.execute(job); jobs.add(job); } // When all RepairJobs are done without error, cleanup and set the final result Futures.addCallback(Futures.allAsList(jobs), new FutureCallback<List<RepairResult>>() { public void onSuccess(List<RepairResult> results) { // this repair session is completed logger.info("[repair #{}] {}", getId(), "Session completed successfully"); Tracing.traceRepair("Completed sync of range {}", range); set(new RepairSessionResult(id, keyspace, range, results)); taskExecutor.shutdown(); // mark this session as terminated terminate(); } public void onFailure(Throwable t) { logger.error(String.format("[repair #%s] Session completed with the following error", getId()), t); Tracing.traceRepair("Session completed with the following error: {}", t); forceShutdown(t); } }); }