mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-29 22:27:34 +00:00
feat: 为 GroovyTrigger 添加 shutdown 方法.
增加 shutdown 方法用于向触发器发出停止信号, 以后有用.
This commit is contained in:
parent
2f225d27fe
commit
2cd679bcaf
@ -17,4 +17,9 @@ public interface GroovyTrigger {
|
|||||||
*/
|
*/
|
||||||
void run(Closure<?> task);
|
void run(Closure<?> task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭触发器.
|
||||||
|
*/
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,9 @@ public class OnceTrigger implements GroovyTrigger {
|
|||||||
public void run(Closure<?> task) {
|
public void run(Closure<?> task) {
|
||||||
EXECUTOR.execute(task);
|
EXECUTOR.execute(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
// Nothing.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.scheduling.support.CronTrigger;
|
import org.springframework.scheduling.support.CronTrigger;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author LamGC
|
* @author LamGC
|
||||||
*/
|
*/
|
||||||
@ -28,6 +30,9 @@ public class TimerTrigger implements GroovyTrigger {
|
|||||||
SCHEDULER.initialize();
|
SCHEDULER.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CronTrigger trigger;
|
||||||
|
private ScheduledFuture<?> future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定定时时间.
|
* 设定定时时间.
|
||||||
* <p> 只允许在第一次执行时设置.
|
* <p> 只允许在第一次执行时设置.
|
||||||
@ -59,7 +64,14 @@ public class TimerTrigger implements GroovyTrigger {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEDULER.schedule(new TimerTaskRunnable(runnable), trigger);
|
this.future = SCHEDULER.schedule(new TimerTaskRunnable(runnable), trigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
if (this.future != null) {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TimerTaskRunnable implements Runnable {
|
private static class TimerTaskRunnable implements Runnable {
|
||||||
|
Loading…
Reference in New Issue
Block a user