Initial commit

This commit is contained in:
tommyskeff
2023-11-19 20:55:02 +00:00
commit 08e97d81a4
34 changed files with 1807 additions and 0 deletions

View File

@@ -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());
}
};
}
}