mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package dev.tommyjs.futur.scheduler;
|
||||
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public interface Scheduler {
|
||||
|
||||
Logger LOGGER = LoggerFactory.getLogger(Scheduler.class);
|
||||
|
||||
void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
default @NotNull Runnable wrapExceptions(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
return () -> {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception in scheduled task: {}", e.getClass().getName());
|
||||
LOGGER.error(trace.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user