diff options
author | 2017-08-10 14:59:46 +0200 | |
---|---|---|
committer | 2017-08-11 11:57:33 +0200 | |
commit | 4cc2e579d77602386c4c1e8e8855f00a38db1e2a (patch) | |
tree | 1bf67aac3712db8cf7e0eefacec9017b3d228777 /src/main/java | |
parent | d7f5c120417bc2d2344dfb285322355f225d9153 (diff) |
Move anonymous inner class to nested class
PiperOrigin-RevId: 164844520
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java | 180 |
1 files changed, 100 insertions, 80 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java index 5aacd8ab67..609b201e28 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java @@ -72,86 +72,9 @@ public abstract class AbstractSpawnStrategy implements SandboxedSpawnActionConte actionExecutionContext.reportSubcommand(spawn); } final Duration timeout = Spawns.getTimeout(spawn); - SpawnExecutionPolicy policy = new SpawnExecutionPolicy() { - private final int id = execCount.incrementAndGet(); - // Memoize the input mapping so that prefetchInputs can reuse it instead of recomputing it. - // TODO(ulfjack): Guard against client modification of this map. - private SortedMap<PathFragment, ActionInput> lazyInputMapping; - - @Override - public int getId() { - return id; - } - - @Override - public void prefetchInputs() throws IOException { - if (Spawns.shouldPrefetchInputsForLocalExecution(spawn)) { - // TODO(philwo): Benchmark whether using an ExecutionService to do multiple operations in - // parallel speeds up prefetching of inputs. - // TODO(philwo): Do we have to expand middleman artifacts here? - actionExecutionContext.getActionInputPrefetcher().prefetchFiles( - Iterables.filter(getInputMapping().values(), Predicates.notNull())); - } - } - - @Override - public ActionInputFileCache getActionInputFileCache() { - return actionExecutionContext.getActionInputFileCache(); - } - - @Override - public ArtifactExpander getArtifactExpander() { - return actionExecutionContext.getArtifactExpander(); - } - - @Override - public void lockOutputFiles() throws InterruptedException { - Class<? extends SpawnActionContext> token = AbstractSpawnStrategy.this.getClass(); - if (writeOutputFiles != null - && writeOutputFiles.get() != token - && !writeOutputFiles.compareAndSet(null, token)) { - throw new InterruptedException(); - } - } - - @Override - public Duration getTimeout() { - return timeout; - } - - @Override - public FileOutErr getFileOutErr() { - return actionExecutionContext.getFileOutErr(); - } - - @Override - public SortedMap<PathFragment, ActionInput> getInputMapping() throws IOException { - if (lazyInputMapping == null) { - lazyInputMapping = spawnInputExpander.getInputMapping( - spawn, - actionExecutionContext.getArtifactExpander(), - actionExecutionContext.getActionInputFileCache(), - actionExecutionContext.getContext(FilesetActionContext.class)); - } - return lazyInputMapping; - } - - @Override - public void report(ProgressStatus state, String name) { - // TODO(ulfjack): We should report more details to the UI. - EventBus eventBus = actionExecutionContext.getEventBus(); - switch (state) { - case EXECUTING: - eventBus.post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), name)); - break; - case SCHEDULING: - eventBus.post(ActionStatusMessage.schedulingStrategy(spawn.getResourceOwner())); - break; - default: - break; - } - } - }; + SpawnExecutionPolicy policy = + new SpawnExecutionPolicyImpl( + spawn, actionExecutionContext, writeOutputFiles, timeout); SpawnResult result; try { result = spawnRunner.exec(spawn, policy); @@ -168,4 +91,101 @@ public abstract class AbstractSpawnStrategy implements SandboxedSpawnActionConte message, result, /*forciblyRunRemotely=*/false, /*catastrophe=*/false); } } + + private final class SpawnExecutionPolicyImpl implements SpawnExecutionPolicy { + private final Spawn spawn; + private final ActionExecutionContext actionExecutionContext; + private final AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles; + private final Duration timeout; + + private final int id = execCount.incrementAndGet(); + // Memoize the input mapping so that prefetchInputs can reuse it instead of recomputing it. + // TODO(ulfjack): Guard against client modification of this map. + private SortedMap<PathFragment, ActionInput> lazyInputMapping; + + public SpawnExecutionPolicyImpl( + Spawn spawn, + ActionExecutionContext actionExecutionContext, + AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles, + Duration timeout) { + this.spawn = spawn; + this.actionExecutionContext = actionExecutionContext; + this.writeOutputFiles = writeOutputFiles; + this.timeout = timeout; + } + + @Override + public int getId() { + return id; + } + + @Override + public void prefetchInputs() throws IOException { + if (Spawns.shouldPrefetchInputsForLocalExecution(spawn)) { + // TODO(philwo): Benchmark whether using an ExecutionService to do multiple operations in + // parallel speeds up prefetching of inputs. + // TODO(philwo): Do we have to expand middleman artifacts here? + actionExecutionContext.getActionInputPrefetcher().prefetchFiles( + Iterables.filter(getInputMapping().values(), Predicates.notNull())); + } + } + + @Override + public ActionInputFileCache getActionInputFileCache() { + return actionExecutionContext.getActionInputFileCache(); + } + + @Override + public ArtifactExpander getArtifactExpander() { + return actionExecutionContext.getArtifactExpander(); + } + + @Override + public void lockOutputFiles() throws InterruptedException { + Class<? extends SpawnActionContext> token = AbstractSpawnStrategy.this.getClass(); + if (writeOutputFiles != null + && writeOutputFiles.get() != token + && !writeOutputFiles.compareAndSet(null, token)) { + throw new InterruptedException(); + } + } + + @Override + public Duration getTimeout() { + return timeout; + } + + @Override + public FileOutErr getFileOutErr() { + return actionExecutionContext.getFileOutErr(); + } + + @Override + public SortedMap<PathFragment, ActionInput> getInputMapping() throws IOException { + if (lazyInputMapping == null) { + lazyInputMapping = spawnInputExpander.getInputMapping( + spawn, + actionExecutionContext.getArtifactExpander(), + actionExecutionContext.getActionInputFileCache(), + actionExecutionContext.getContext(FilesetActionContext.class)); + } + return lazyInputMapping; + } + + @Override + public void report(ProgressStatus state, String name) { + // TODO(ulfjack): We should report more details to the UI. + EventBus eventBus = actionExecutionContext.getEventBus(); + switch (state) { + case EXECUTING: + eventBus.post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), name)); + break; + case SCHEDULING: + eventBus.post(ActionStatusMessage.schedulingStrategy(spawn.getResourceOwner())); + break; + default: + break; + } + } + } } |