ScanScheduler.java
2.51 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.scheduler.ScheduleOptions
* org.apache.sling.commons.scheduler.Scheduler
*/
package com.adobe.aemfd.watchfolder.job;
import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.distribution.JobDistributor;
import com.adobe.aemfd.watchfolder.job.FileScanJobImpl;
import com.adobe.aemfd.watchfolder.util.TopologyHelper;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.scheduler.ScheduleOptions;
import org.apache.sling.commons.scheduler.Scheduler;
@Component(immediate=1)
@Service(value={ScanScheduler.class})
public class ScanScheduler {
private static final String SCAN_JOB_PREFIX = "WF_SCAN_JOB_";
@Reference
private Scheduler scheduler;
@Reference
private TopologyHelper topologyHelper;
@Reference
private JobDistributor jobDistributor;
public void scheduleScan(WatchFolderConfiguration config) throws Exception {
ScheduleOptions opts = this.scheduler.NOW(-1, config.getPollInterval()).onLeaderOnly(true).name("WF_SCAN_JOB_" + config.getId()).canRunConcurrently(false);
FileScanJobImpl job = new FileScanJobImpl(config, this.jobDistributor, this.topologyHelper);
this.scheduler.schedule((Object)job, opts);
}
public void tearDown(String wfId) {
this.scheduler.unschedule("WF_SCAN_JOB_" + wfId);
}
protected void bindScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
}
protected void unbindScheduler(Scheduler scheduler) {
if (this.scheduler == scheduler) {
this.scheduler = null;
}
}
protected void bindTopologyHelper(TopologyHelper topologyHelper) {
this.topologyHelper = topologyHelper;
}
protected void unbindTopologyHelper(TopologyHelper topologyHelper) {
if (this.topologyHelper == topologyHelper) {
this.topologyHelper = null;
}
}
protected void bindJobDistributor(JobDistributor jobDistributor) {
this.jobDistributor = jobDistributor;
}
protected void unbindJobDistributor(JobDistributor jobDistributor) {
if (this.jobDistributor == jobDistributor) {
this.jobDistributor = null;
}
}
}