m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/RecursiveScheduledTask.java
blob: 07e1fd457ec8e81eb70e25050a1014bd90f49c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package pl.edu.mimuw.cloudatlas.agent.modules;

import java.util.function.Supplier;

import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage;

public class RecursiveScheduledTask extends TimerScheduledTask {
    private long delay;
    private Supplier<TimerScheduledTask> taskSupplier;

    public RecursiveScheduledTask(long delay, Supplier<TimerScheduledTask> taskSupplier) {
        this.delay = delay;
        this.taskSupplier = taskSupplier;
    }

    public void run() {
        try {
            TimerScheduledTask task = taskSupplier.get();
            task.setScheduler(scheduler);
            task.run();
            sendMessage(new TimerSchedulerMessage("", 0, "", delay, 0, new RecursiveScheduledTask(delay, taskSupplier)));
        } catch (InterruptedException e) {
            System.out.println("Caught interrupted exception while running RecursiveScheduledTask");
        }
    }
}