Ignore:
Timestamp:
01/09/25 18:31:38 (6 days ago)
Author:
Kristijan <kristijanzafirovski26@…>
Branches:
master
Children:
53bad7e
Parents:
d4d8f61
Message:

pred-finalna

File:
1 edited

Legend:

Unmodified
Added
Removed
  • backend/GlobeGuru-backend/src/main/java/Scraper.java

    rd4d8f61 rc164f8f  
    77import java.util.Iterator;
    88import java.util.List;
     9import java.util.concurrent.Callable;
    910import java.util.concurrent.ConcurrentLinkedQueue;
    1011import java.util.concurrent.CountDownLatch;
    1112
    12 public class Scraper extends Thread {
     13public class Scraper implements Callable<Void> {
     14
    1315    private List<String> urls;
    14     private String destination;
    15     private String departureDate;
    16     private int numberOfPeople;
    1716    private ConcurrentLinkedQueue<Option> optionsQueue;
    1817    private CountDownLatch latch;
    1918
    20     public Scraper(String destination, String departureDate, int numberOfPeople) {
     19    public Scraper() {
    2120        urls = new ArrayList<>();
    2221        this.optionsQueue = new ConcurrentLinkedQueue<>();
    2322        ObjectMapper mapper = new ObjectMapper();
    2423        try {
    25             JsonNode root = mapper.readTree(new File("src/main/java/URLsJSON.json"));
     24            ClassLoader classLoader = getClass().getClassLoader();
     25            JsonNode root = mapper.readTree(new File(classLoader.getResource("URLsJSON.json").getFile()));
     26
    2627            JsonNode urlNode = root.get("agencyurls");
    2728            if (urlNode.isArray()) {
     
    3637            throw new RuntimeException(e);
    3738        }
    38         this.destination = destination;
    39         this.departureDate = departureDate;
    40         this.numberOfPeople = numberOfPeople;
    4139        this.latch = new CountDownLatch(urls.size());
    4240    }
    4341
    44     @Override
    45     public void run() {
     42
     43    public Void call() {
    4644        System.out.println("Scraper has started ");
    4745        for (String url : urls) {
    48             new ScraperThread(url, destination, departureDate, numberOfPeople, optionsQueue, latch).start();
     46            new ScraperThread(url, optionsQueue, latch).start();
    4947        }
    50     }
    51     public List<Option> getOptions() {
    52         try {
    53             latch.await();  // Wait for all threads to finish
    54         } catch (InterruptedException e) {
    55             e.printStackTrace();
    56         }
    57         return new ArrayList<>(optionsQueue);
     48        return null;
    5849    }
    5950}
Note: See TracChangeset for help on using the changeset viewer.