Package com.plotsquared.core.util.task
Class TaskManager
java.lang.Object
com.plotsquared.core.util.task.TaskManager
Task manager that handles scheduling of tasks.
Synchronous methods make no guarantee of being scheduled on the
server thread, instead they guarantee that no two synchronous
operations happen at the same time. Implementations of
the task manager might make other guarantees. All asynchronous
operations will happen on another thread, no matter where
they're scheduled from.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddTask(@NonNull PlotSquaredTask task, int id)Add a task to the task mapstatic voidaddToTeleportQueue(@NonNull String string)Add a string to the teleport queueabstract <T> Future<T>callMethodSync(@NonNull Callable<T> method)Call a method synchronously and return a future with the result of the resultstatic @Nullable TaskManager<T> CompletableFuture<Void>objectTask(@NonNull Collection<T> objects, @NonNull RunnableVal<T> task)Break up a series of tasks so that they can run without lagging the serverstatic booleanremoveFromTeleportQueue(@NonNull String string)Remove a string from the teleport queuestatic @Nullable PlotSquaredTaskremoveTask(int id)Remove a task from the task map and return the stored valuestatic voidRun a synchronous task.static voidrunTaskAsync(@Nullable Runnable runnable)Run an asynchronous task.static voidrunTaskLater(@Nullable Runnable runnable, @NonNull TaskTime taskTime)Run a synchronous task after a given delay.static voidrunTaskLaterAsync(@Nullable Runnable runnable, @NonNull TaskTime taskTime)Run an asynchronous task after a given delay.static @NonNull PlotSquaredTaskrunTaskRepeat(@Nullable Runnable runnable, @NonNull TaskTime taskTime)Run a repeating synchronous task.static voidsetPlatformImplementation(@NonNull TaskManager implementation)<T> TMake a synchronous method call and return the resultabstract <T> TMake a synchronous method call and return the resultabstract voidRun a synchronous task.abstract voidRun an asynchronous task.abstract voidRun a synchronous task after a given delay.abstract voidtaskLaterAsync(@NonNull Runnable runnable, @NonNull TaskTime taskTime)Run an asynchronous task after a given delay.abstract PlotSquaredTasktaskRepeat(@NonNull Runnable runnable, @NonNull TaskTime taskTime)Run a repeating synchronous task.abstract PlotSquaredTasktaskRepeatAsync(@NonNull Runnable runnable, @NonNull TaskTime taskTime)Run a repeating asynchronous task.
-
Field Details
-
index
-
-
Constructor Details
-
TaskManager
public TaskManager()
-
-
Method Details
-
addToTeleportQueue
Add a string to the teleport queue- Parameters:
string- String to add
-
removeFromTeleportQueue
Remove a string from the teleport queue- Parameters:
string- String to remove returntrueif the value was stored in the map, orfalse- Returns:
- if string was actually removed
-
addTask
Add a task to the task map- Parameters:
task- Taskid- Task ID
-
removeTask
Remove a task from the task map and return the stored value- Parameters:
id- Task ID- Returns:
- Task if stored, or
null
-
runTaskRepeat
public static @NonNull PlotSquaredTask runTaskRepeat(@Nullable Runnable runnable, @NonNull TaskTime taskTime)Run a repeating synchronous task. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to runtaskTime- Task interval- Returns:
- Created task object, can be used to cancel the task
-
runTaskAsync
Run an asynchronous task. This will never run on the server thread- Parameters:
runnable- Task to run
-
runTask
Run a synchronous task. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to run
-
runTaskLater
Run a synchronous task after a given delay. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to runtaskTime- Task delay
-
runTaskLaterAsync
Run an asynchronous task after a given delay. This will never run on the server thread- Parameters:
runnable- Task to runtaskTime- Task delay
-
getPlatformImplementation
-
setPlatformImplementation
-
objectTask
public <T> CompletableFuture<Void> objectTask(@NonNull Collection<T> objects, @NonNull RunnableVal<T> task)Break up a series of tasks so that they can run without lagging the server- Type Parameters:
T- Object type- Parameters:
objects- Objects to perform the task ontask- Task to perform- Returns:
- Future that completes when the tasks are done
-
sync
Make a synchronous method call and return the result- Type Parameters:
T- Return type- Parameters:
function- Method to call- Returns:
- Method result
- Throws:
Exception- If the call fails
-
sync
Make a synchronous method call and return the result- Type Parameters:
T- Return type- Parameters:
function- Method to calltimeout- Timeout (ms)- Returns:
- Method result
- Throws:
Exception- If the call fails
-
callMethodSync
Call a method synchronously and return a future with the result of the result- Type Parameters:
T- Return type- Parameters:
method- Method to be ran synchronously- Returns:
- Future completing with the result
-
taskRepeat
Run a repeating synchronous task. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to runtaskTime- Task interval- Returns:
- Created task object, can be used to cancel the task
-
taskRepeatAsync
public abstract PlotSquaredTask taskRepeatAsync(@NonNull Runnable runnable, @NonNull TaskTime taskTime)Run a repeating asynchronous task. This will never run on the server thread- Parameters:
runnable- Task to runtaskTime- Task interval- Returns:
- Created task object, can be used to cancel the task
-
taskAsync
Run an asynchronous task. This will never run on the server thread- Parameters:
runnable- Task to run
-
task
Run a synchronous task. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to run
-
taskLater
Run a synchronous task after a given delay. If using a platform scheduler, this is guaranteed to run on the server thread- Parameters:
runnable- Task to runtaskTime- Task delay
-
taskLaterAsync
Run an asynchronous task after a given delay. This will never run on the server thread- Parameters:
runnable- Task to runtaskTime- Task delay
-