1919import com .google .common .base .Preconditions ;
2020import com .google .edwmigration .dumper .application .dumper .handle .Handle ;
2121import com .google .edwmigration .dumper .plugin .ext .jdk .concurrent .ExecutorManager ;
22- import java .util .concurrent .Callable ;
22+ import java .io .IOException ;
23+ import java .util .concurrent .ExecutionException ;
24+ import javax .annotation .Nonnull ;
25+ import javax .annotation .Nullable ;
2326import org .apache .commons .csv .CSVPrinter ;
2427
25- // Redshift is really slow, and is the only thing that uses this.
2628public class ParallelTaskGroup extends TaskGroup {
2729
2830 public ParallelTaskGroup (String name ) {
@@ -42,21 +44,21 @@ public void addTask(Task<?> task) {
4244 super .addTask (task );
4345 }
4446
45- private static class TaskRunner < T > implements Callable < T > {
47+ private static class TaskRunner {
4648
47- private final TaskRunContext context ;
48- private final Task <T > task ;
49- private final CSVPrinter printer ;
49+ @ Nonnull private final TaskRunContext context ;
50+ @ Nonnull private final Task <? > task ;
51+ @ Nonnull private final CSVPrinter printer ;
5052
51- public TaskRunner (TaskRunContext context , Task <T > task , CSVPrinter printer ) {
53+ public TaskRunner (
54+ @ Nonnull TaskRunContext context , @ Nonnull Task <?> task , @ Nonnull CSVPrinter printer ) {
5255 this .context = context ;
5356 this .task = task ;
5457 this .printer = printer ;
5558 }
5659
57- @ Override
58- public T call () throws Exception {
59- T result = context .runChildTask (task );
60+ public @ Nullable Object call () throws IOException {
61+ Object result = context .runChildTask (task );
6062 TaskState state = context .getTaskState (task );
6163 synchronized (printer ) {
6264 printer .printRecord (task , state );
@@ -66,15 +68,16 @@ public T call() throws Exception {
6668 }
6769
6870 @ Override
69- @ SuppressWarnings (
70- "FutureReturnValueIgnored" ) // It's an ExecutorManager, which tracks the Future internally.
71- protected void doRun ( TaskRunContext context , CSVPrinter printer , Handle handle ) throws Exception {
71+ protected void doRun (
72+ @ Nonnull TaskRunContext context , @ Nonnull CSVPrinter printer , @ Nonnull Handle handle )
73+ throws ExecutionException , InterruptedException {
7274 // Throws ExecutionException if any sub-task threw. However, runChildTask() is nothrow, so that
7375 // never happens.
7476 // We safely publish the CSVPrinter to the ExecutorManager.
7577 try (ExecutorManager executorManager = new ExecutorManager (context .getExecutorService ())) {
7678 for (Task <?> task : getTasks ()) {
77- executorManager .submit (new TaskRunner <>(context , task , printer ));
79+ TaskRunner runner = new TaskRunner (context , task , printer );
80+ executorManager .execute (runner ::call );
7881 }
7982 }
8083 // We now, by the t-w-r, safely collect the CSVPrinter from the sub-threads.
0 commit comments