shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.scheduler.impl;
 
import com.walker.scheduler.util.OptionUtils;
 
/**
 * 平台实现的“采集类型”调度器,特点是:无限循环,持续执行,无需设置周期。
 * @author 时克英
 * @date 2018-12-28
 *
 */
public abstract class ForeverScheduler extends TimedScheduler {
 
    // 如果执行调用后,未返回结果数据,就进入休眠(有休眠时间设置)
    private boolean sleepForNotFoundData = true;
    
    /**
     * 设置参数:如果执行调用后,未返回结果数据,就进入休眠(有休眠时间设置)
     * @param sleepForNotFoundData
     */
    public void setSleepForNotFoundData(boolean sleepForNotFoundData) {
        this.sleepForNotFoundData = sleepForNotFoundData;
    }
 
    public ForeverScheduler(int id, String name){
        super(id, name);
        this.setOption(OptionUtils.combineEveryDay24HourOption());
    }
    
    @Override
    protected Object doRunOnce(Object[] inputParams) throws Exception {
        this.firstRunForLazy();
        Object result = this.onProcess(inputParams);
        if(result == null && this.sleepForNotFoundData){
            this.doChangeIntervalTime();
            logger.debug("~~~~~~~~~~~~~~~~~~~~ 没有数据采集,线程休眠一次:" + this.getTimeInterval());
        } else {
            this.doResetIntervalTime();
        }
        
        return result;
    }
 
    @Override
    protected Object[] getRunParameters(Object previousInvokeResult) {
        return null;
    }
 
}