java.lang.Object
me.moros.tasker.executor.SimpleAsyncExecutor
- All Implemented Interfaces:
Executor,AsyncExecutor,TaskExecutor,TickAdapter
A simple async executor implementation that delegates to a
ScheduledExecutorService for repeated tasks.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleanisValid()Check whether this executor can currently schedule and execute tasks.Schedule a repeating task.voidshutdown()Safely shutdown this executor.<V> CompletableFuture<@PolyNull V>Submit a task.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.moros.tasker.executor.AsyncExecutor
repeat, submitMethods inherited from interface me.moros.tasker.executor.TaskExecutor
execute, repeat, repeat, submit, submit, submit, submitMethods inherited from interface me.moros.tasker.executor.TickAdapter
convert, toMillis, toTicks
-
Constructor Details
-
SimpleAsyncExecutor
-
SimpleAsyncExecutor
public SimpleAsyncExecutor()
-
-
Method Details
-
submit
public <V> CompletableFuture<@PolyNull V> submit(Supplier<@PolyNull V> task, long delay, TimeUnit unit) Description copied from interface:TaskExecutorSubmit a task.- Specified by:
submitin interfaceTaskExecutor- Type Parameters:
V- the type of result the task returns- Parameters:
task- the task to submitdelay- the delay before the task is executedunit- the unit of time for delay- Returns:
- the scheduled task as a future
-
repeat
Description copied from interface:TaskExecutorSchedule a repeating task.- Specified by:
repeatin interfaceTaskExecutor- Parameters:
task- the task to scheduledelay- the delay before the first task executionperiod- how often to repeat the taskunit- the unit of time for delay and period- Returns:
- the scheduled task
-
isValid
public boolean isValid()Description copied from interface:TaskExecutorCheck whether this executor can currently schedule and execute tasks. This should return false if it hasn't been initialized or has been terminated.- Specified by:
isValidin interfaceTaskExecutor- Returns:
- whether tasks can be scheduled and executed
-
shutdown
public void shutdown()Description copied from interface:TaskExecutorSafely shutdown this executor.- Specified by:
shutdownin interfaceTaskExecutor
-
checkValid
protected void checkValid()
-