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
49
50
51
52
53
package com.walker.scheduler.impl;
 
import com.walker.scheduler.AbstractScheduler;
 
public abstract class ListeningScheduler extends AbstractScheduler {
 
    public ListeningScheduler(int id, String name
//            , DatabaseStore store
    ) {
        super(id, name);
    }
 
    @Override
    protected Object runTask() throws Exception {
        return null;
    }
 
    @Override
    public void start() {
        if(!started){
            // 
            try {
                this.onStartScheduler();
                logger.info("调度器'" + this.getName() + "'启动......");
                started = true;
                scheduleEngine.setStatusStarted(this.getId());
            } catch (Exception e) {
                throw new IllegalStateException("启动'ListeningScheduler'失败:"+e.getMessage(), e);
            }
        } else {
            throw new IllegalStateException("调度器已启动,调用状态错误。id = " + this.getId());
        }
        startTime = System.currentTimeMillis();
    }
    
    @Override
    public void pause() {
        throw new UnsupportedOperationException("监听类调度器不支持暂停方法");
    }
    
    @Override
    public void stop() {
        this.onStopScheduler();
        started = false;
        this.onStopScheduler();
        scheduleEngine.setStatusStoped(this.getId());
        logger.info("调度器'" + this.getName() + "'被停止运行......");
    }
    
    protected abstract void onStartScheduler() throws Exception;
    
    protected abstract void onStopScheduler();
}