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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addTask
(@NonNull PlotSquaredTask task, int id) Add a task to the task mapstatic void
addToTeleportQueue
(@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 boolean
removeFromTeleportQueue
(@NonNull String string) Remove a string from the teleport queuestatic @Nullable PlotSquaredTask
removeTask
(int id) Remove a task from the task map and return the stored valuestatic void
Run a synchronous task.static void
runTaskAsync
(@Nullable Runnable runnable) Run an asynchronous task.static void
runTaskLater
(@Nullable Runnable runnable, @NonNull TaskTime taskTime) Run a synchronous task after a given delay.static void
runTaskLaterAsync
(@Nullable Runnable runnable, @NonNull TaskTime taskTime) Run an asynchronous task after a given delay.static @NonNull PlotSquaredTask
runTaskRepeat
(@Nullable Runnable runnable, @NonNull TaskTime taskTime) Run a repeating synchronous task.static void
setPlatformImplementation
(@NonNull TaskManager implementation) <T> T
Make a synchronous method call and return the resultabstract <T> T
Make a synchronous method call and return the resultabstract void
Run a synchronous task.abstract void
Run an asynchronous task.abstract void
Run a synchronous task after a given delay.abstract void
taskLaterAsync
(@NonNull Runnable runnable, @NonNull TaskTime taskTime) Run an asynchronous task after a given delay.abstract PlotSquaredTask
taskRepeat
(@NonNull Runnable runnable, @NonNull TaskTime taskTime) Run a repeating synchronous task.abstract PlotSquaredTask
taskRepeatAsync
(@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 returntrue
if 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
-