ScanScheduler.java 2.51 KB
/*
 * 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;
        }
    }
}