if (!servingHostNames.isEmpty()) {
specifications = Iterables.concat(specifications, ImmutableList.of(
createWebappSpec(ProgramType.WEBAPP.toString().toLowerCase())));
}
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(10, Threads.createDaemonThreadFactory("program-gen-%d"))
);
try {
List<ListenableFuture<Location>> futures = Lists.newArrayList();
for (final ProgramSpecification spec: specifications) {
ListenableFuture<Location> future = executorService.submit(
new Callable<Location>() {
@Override
public Location call() throws Exception {
ProgramType type = ProgramTypes.fromSpecification(spec);
String name = String.format(Locale.ENGLISH, "%s/%s", type, applicationName);
Location programDir = newOutputDir.append(name);
if (!programDir.exists()) {
programDir.mkdirs();
}
Location output = programDir.append(String.format("%s.jar", spec.getName()));
return ProgramBundle.create(o.getApplicationId(), bundler, output, spec.getName(),
spec.getClassName(), type, appSpec);
}
});
futures.add(future);
}
for (Location jarLocation : Futures.allAsList(futures).get()) {
programs.add(Programs.create(jarLocation, null));
}
} finally {
executorService.shutdown();
}
// Emits the received specification with programs.
emit(new ApplicationWithPrograms(o, programs.build()));
}