Check if delegated `JobListener`s implement `Closeable` and if they do, call `close()`.
package gobblin.runtime.listeners;
+import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Callable;
@@ -172,6 +173,25 @@ public class JobListeners {
}
} finally {
ExecutorsUtils.shutdownExecutorService(this.executor, Optional.of(LOGGER));
+ closeJobListeners();
+ }
+ }
+
+ private void closeJobListeners() throws IOException {
+ IOException exception = null;
+ for (JobListener jobListener : this.jobListeners) {
+ if (jobListener instanceof Closeable) {
+ try {
+ ((Closeable) jobListener).close();
+ } catch (IOException e) {
+ if (exception == null) {
+ exception = e;
+ }
+ }
+ }
+ }
+ if (exception != null) {
+ throw exception;
}
}
}
