Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProcessFiles {
- private static final Logger logger = LoggerFactory.getLogger(ProcessFiles.class.getSimpleName());
- public static void main(String[] args) throws IOException, InterruptedException {
- long startTime = System.currentTimeMillis();
- logger.info("Creating actor system");
- ActorSystem system = ActorSystem.create("actor_system");
- Set<String> files = new HashSet<>();
- Stream<String> stringStream = Files.lines(Paths.get(fileName));
- stringStream.forEach(line -> files.addAll(Arrays.asList(line.split(","))));
- List<CompletableFuture<Object>> futureList = new ArrayList<>();
- files.forEach((String file) -> {
- ActorRef actorRef = system.actorOf(Props.create(ProcessFile.class, file));
- futureList.add(PatternsCS.ask(actorRef, DEFAULT_TIMEOUT).toCompletableFuture());
- });
- boolean isDone;
- do {
- Thread.sleep(30000);
- isDone = true;
- int count = 0;
- for (CompletableFuture<Object> future : futureList) {
- isDone = isDone & (future.isDone() || future.isCompletedExceptionally() || future.isCancelled());
- if (future.isDone() || future.isCompletedExceptionally() || future.isCancelled()) {
- ++count;
- }
- }
- logger.info("Process is completed for " + count + " files out of " + files.size() + " files.");
- } while (!isDone);
- logger.info("Process is done in " + (System.currentTimeMillis() - startTime) + " ms");
- system.terminate();
- }
- }
Add Comment
Please, Sign In to add comment