src/main/java/org/embulk/output/multi/AsyncRunControl.java in embulk-output-multi-0.2.2 vs src/main/java/org/embulk/output/multi/AsyncRunControl.java in embulk-output-multi-0.3.0

- old
+ new

@@ -20,24 +20,25 @@ private final MultiOutputPlugin.PluginTask task; private final OutputPlugin.Control control; private final CountDownLatch latch; private final ConcurrentMap<String, TaskSource> taskSources; private final ExecutorService executorService; - private Future<List<TaskReport>> result; + private final Future<List<TaskReport>> result; static AsyncRunControl start(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) { - return new AsyncRunControl(task, control).start(); + return new AsyncRunControl(task, control); } private AsyncRunControl(MultiOutputPlugin.PluginTask task, OutputPlugin.Control control) { this.task = task; this.control = control; this.latch = new CountDownLatch(task.getOutputConfigs().size()); this.taskSources = new ConcurrentHashMap<>(task.getOutputConfigs().size()); this.executorService = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat(THREAD_NAME_FORMAT).build() ); + this.result = executorService.submit(new RunControl()); } void cancel() { result.cancel(true); } @@ -51,14 +52,9 @@ try { return result.get(); } finally { executorService.shutdown(); } - } - - private AsyncRunControl start() { - this.result = executorService.submit(new RunControl()); - return this; } private class RunControl implements Callable<List<TaskReport>> { @Override public List<TaskReport> call() throws Exception {