Class ExecutorSpigot
java.lang.Object
nl.pim16aap2.animatedarchitecture.spigot.util.implementations.ExecutorSpigot
- All Implemented Interfaces:
IDebuggable, IExecutor, IRestartable
@Singleton
public final class ExecutorSpigot
extends Object
implements IExecutor, IRestartable, IDebuggable
Implementation of
IExecutor for the Spigot platform.-
Constructor Summary
ConstructorsConstructorDescriptionExecutorSpigot(org.bukkit.plugin.java.JavaPlugin plugin, long mainThreadId, RestartableHolder restartableHolder) -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels a task.Gets the debug information for this object.A virtual executor that creates a new virtual thread for each task.voidHandles the initialization.booleanisMainThread(long threadId) Checks if a thread is the main thread.intSchedules an action to be run asynchronously.voidrunAsyncLater(Runnable runnable, long delay) Schedules a repeatedRunnableto be run asynchronously.voidrunAsyncLater(TimerTask timerTask, long delay) Schedules a repeatedTimerTaskto be run asynchronously.intrunAsyncRepeated(Runnable runnable, long delay, long period) Schedules a repeatedRunnableto be run asynchronously.intrunAsyncRepeated(TimerTask timerTask, long delay, long period) Schedules a repeatedTimerTaskto be run asynchronously.intSchedules an action to be run on the main thread.voidrunSyncLater(Runnable runnable, long delay) Schedules a repeatedRunnableto be run on the main thread.voidrunSyncLater(TimerTask timerTask, long delay) Schedules a repeatedTimerTaskto be run on the main thread.intrunSyncRepeated(Runnable runnable, long delay, long period) Schedules a repeatedRunnableto be run on the main thread.intrunSyncRepeated(TimerTask timerTask, long delay, long period) Schedules a repeatedTimerTaskto be run on the main thread.voidscheduleOnMainThread(Runnable runnable) Schedules an action to be run on the main thread.<T> CompletableFuture<T> scheduleOnMainThread(Supplier<T> supplier) Schedules a task to be run on the main thread.voidshutDown()Handles a shutdown.<T> CompletableFuture<T> supplyAsync(Supplier<T> supplier) Schedules a task to be run on the main thread.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IExecutor
assertMainThread, assertMainThread, assertNotMainThread, assertNotMainThread, composeOnMainThread, isMainThread, runOnMainThread, runOnMainThread, runOnMainThreadWithResponse
-
Constructor Details
-
ExecutorSpigot
@Inject public ExecutorSpigot(org.bukkit.plugin.java.JavaPlugin plugin, @Named("mainThreadId") long mainThreadId, RestartableHolder restartableHolder)
-
-
Method Details
-
getVirtualExecutor
Description copied from interface:IExecutorA virtual executor that creates a new virtual thread for each task.This should be used for all tasks that spend a lot of time waiting (e.g. I/O operations).
This executor will be shut down and replaced when the plugin restarts. This means that all tasks that are still running when the plugin restarts will be cancelled. If this is not desired, a custom executor should be created.
- Specified by:
getVirtualExecutorin interfaceIExecutor- Returns:
- The virtual executor.
-
scheduleOnMainThread
Description copied from interface:IExecutorSchedules a task to be run on the main thread.- Specified by:
scheduleOnMainThreadin interfaceIExecutor- Parameters:
supplier- A function returning the value to be used to complete the returned IMainThreadExecutor.- Returns:
- The result of the action.
-
scheduleOnMainThread
Description copied from interface:IExecutorSchedules an action to be run on the main thread.- Specified by:
scheduleOnMainThreadin interfaceIExecutor
-
supplyAsync
Description copied from interface:IExecutorSchedules a task to be run on the main thread.- Specified by:
supplyAsyncin interfaceIExecutor- Parameters:
supplier- A function returning the value to be used to complete the returned IMainThreadExecutor.- Returns:
- The result of the action.
-
runAsync
-
runSync
-
runAsyncRepeated
Description copied from interface:IExecutorSchedules a repeatedTimerTaskto be run asynchronously.- Specified by:
runAsyncRepeatedin interfaceIExecutor- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runAsyncRepeated
Description copied from interface:IExecutorSchedules a repeatedRunnableto be run asynchronously.- Specified by:
runAsyncRepeatedin interfaceIExecutor- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runSyncRepeated
Description copied from interface:IExecutorSchedules a repeatedTimerTaskto be run on the main thread.- Specified by:
runSyncRepeatedin interfaceIExecutor- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runSyncRepeated
Description copied from interface:IExecutorSchedules a repeatedRunnableto be run on the main thread.- Specified by:
runSyncRepeatedin interfaceIExecutor- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runAsyncLater
Description copied from interface:IExecutorSchedules a repeatedTimerTaskto be run asynchronously.- Specified by:
runAsyncLaterin interfaceIExecutor- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runAsyncLater
Description copied from interface:IExecutorSchedules a repeatedRunnableto be run asynchronously.- Specified by:
runAsyncLaterin interfaceIExecutor- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runSyncLater
Description copied from interface:IExecutorSchedules a repeatedTimerTaskto be run on the main thread.- Specified by:
runSyncLaterin interfaceIExecutor- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runSyncLater
Description copied from interface:IExecutorSchedules a repeatedRunnableto be run on the main thread.- Specified by:
runSyncLaterin interfaceIExecutor- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
cancel
-
isMainThread
public boolean isMainThread(long threadId) Description copied from interface:IExecutorChecks if a thread is the main thread.- Specified by:
isMainThreadin interfaceIExecutor- Parameters:
threadId- The ID of the thread to compare.- Returns:
- True if the thread is the main thread.
-
initialize
public void initialize()Description copied from interface:IRestartableHandles the initialization.- Specified by:
initializein interfaceIRestartable
-
shutDown
public void shutDown()Description copied from interface:IRestartableHandles a shutdown.- Specified by:
shutDownin interfaceIRestartable
-
getDebugInformation
Description copied from interface:IDebuggableGets the debug information for this object.- Specified by:
getDebugInformationin interfaceIDebuggable- Returns:
- The debug information or null if there's nothing to log at this time.
-