package com.sourcefellows.patterns.command;

import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

public class Main {

    public static void main(String[] args) {

        List<String> urlsToCrawl = List.of("https://www.source-fellows.com");

        var collector = new WebCrawler();

        try (var executor =
                     new ThreadPoolExecutor(20, 20,
                             10, MILLISECONDS,
                             new LinkedBlockingDeque<>())) {

            for (String url : urlsToCrawl) {
                executor.execute(new CrawlCommand(url, collector));
            }

        }

        try (var executor =
                     new ThreadPoolExecutor(20, 20,
                             10, MILLISECONDS,
                             new LinkedBlockingDeque<>())) {

            for (String url : urlsToCrawl) {
                executor.execute(() -> collector.crawl(url));
            }

        }

    }

}