new Main().go();
}
void go() {
final FileWriter task = new FileWriter(queue);
fileWritingService.submit(task);
List<CrawlerTask> callables = callables();
List<ListenableFuture<Map<String, Object>>> futures = Lists.transform(callables, new Function<CrawlerTask,
ListenableFuture<Map<String, Object>>>() {
@Override
public ListenableFuture<Map<String, Object>> apply(CrawlerTask input) {
return executorService.submit(input);
}
});
ImmutableList.copyOf(Lists.transform(futures, new Function<ListenableFuture<Map<String, Object>>,
FutureCallback<Map<String, Object>>>() {
@Override
public FutureCallback<Map<String, Object>> apply(ListenableFuture<Map<String, Object>> input) {
ExecutionCallback executionCallback = new ExecutionCallback(queue);
Futures.addCallback(input, executionCallback);
return executionCallback;
}
}));
ListenableFuture<List<Map<String, Object>>> listListenableFuture = Futures.successfulAsList(futures);
Futures.addCallback(listListenableFuture, new FutureCallback<List<Map<String, Object>>>() {
@Override
public void onSuccess(List<Map<String, Object>> result) {
task.finished();
executorService.shutdown();
fileWritingService.shutdown();
}
@Override