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 Details

    • ExecutorSpigot

      @Inject public ExecutorSpigot(org.bukkit.plugin.java.JavaPlugin plugin, @Named("mainThreadId") long mainThreadId, RestartableHolder restartableHolder)
  • Method Details

    • getVirtualExecutor

      public ExecutorService getVirtualExecutor()
      Description copied from interface: IExecutor
      A 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:
      getVirtualExecutor in interface IExecutor
      Returns:
      The virtual executor.
    • scheduleOnMainThread

      public <T> CompletableFuture<T> scheduleOnMainThread(Supplier<T> supplier)
      Description copied from interface: IExecutor
      Schedules a task to be run on the main thread.
      Specified by:
      scheduleOnMainThread in interface IExecutor
      Parameters:
      supplier - A function returning the value to be used to complete the returned IMainThreadExecutor.
      Returns:
      The result of the action.
    • scheduleOnMainThread

      public void scheduleOnMainThread(Runnable runnable)
      Description copied from interface: IExecutor
      Schedules an action to be run on the main thread.
      Specified by:
      scheduleOnMainThread in interface IExecutor
    • supplyAsync

      public <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier)
      Description copied from interface: IExecutor
      Schedules a task to be run on the main thread.
      Specified by:
      supplyAsync in interface IExecutor
      Parameters:
      supplier - A function returning the value to be used to complete the returned IMainThreadExecutor.
      Returns:
      The result of the action.
    • runAsync

      public int runAsync(Runnable runnable)
      Description copied from interface: IExecutor
      Schedules an action to be run asynchronously.
      Specified by:
      runAsync in interface IExecutor
      Parameters:
      runnable - The action to run.
      Returns:
      The ID of the task.
    • runSync

      public int runSync(Runnable runnable)
      Description copied from interface: IExecutor
      Schedules an action to be run on the main thread.
      Specified by:
      runSync in interface IExecutor
      Parameters:
      runnable - The action to run.
      Returns:
      The ID of the task.
    • runAsyncRepeated

      public int runAsyncRepeated(TimerTask timerTask, long delay, long period)
      Description copied from interface: IExecutor
      Schedules a repeated TimerTask to be run asynchronously.
      Specified by:
      runAsyncRepeated in interface IExecutor
      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

      public int runAsyncRepeated(Runnable runnable, long delay, long period)
      Description copied from interface: IExecutor
      Schedules a repeated Runnable to be run asynchronously.
      Specified by:
      runAsyncRepeated in interface IExecutor
      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

      public int runSyncRepeated(TimerTask timerTask, long delay, long period)
      Description copied from interface: IExecutor
      Schedules a repeated TimerTask to be run on the main thread.
      Specified by:
      runSyncRepeated in interface IExecutor
      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

      public int runSyncRepeated(Runnable runnable, long delay, long period)
      Description copied from interface: IExecutor
      Schedules a repeated Runnable to be run on the main thread.
      Specified by:
      runSyncRepeated in interface IExecutor
      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

      public void runAsyncLater(TimerTask timerTask, long delay)
      Description copied from interface: IExecutor
      Schedules a repeated TimerTask to be run asynchronously.
      Specified by:
      runAsyncLater in interface IExecutor
      Parameters:
      timerTask - The task to run.
      delay - The delay in milliseconds before the task is to be executed.
    • runAsyncLater

      public void runAsyncLater(Runnable runnable, long delay)
      Description copied from interface: IExecutor
      Schedules a repeated Runnable to be run asynchronously.
      Specified by:
      runAsyncLater in interface IExecutor
      Parameters:
      runnable - The task to run.
      delay - The delay in milliseconds before the task is to be executed.
    • runSyncLater

      public void runSyncLater(TimerTask timerTask, long delay)
      Description copied from interface: IExecutor
      Schedules a repeated TimerTask to be run on the main thread.
      Specified by:
      runSyncLater in interface IExecutor
      Parameters:
      timerTask - The task to run.
      delay - The delay in milliseconds before the task is to be executed.
    • runSyncLater

      public void runSyncLater(Runnable runnable, long delay)
      Description copied from interface: IExecutor
      Schedules a repeated Runnable to be run on the main thread.
      Specified by:
      runSyncLater in interface IExecutor
      Parameters:
      runnable - The task to run.
      delay - The delay in milliseconds before the task is to be executed.
    • cancel

      public void cancel(TimerTask timerTask, int taskID)
      Description copied from interface: IExecutor
      Cancels a task.
      Specified by:
      cancel in interface IExecutor
      Parameters:
      timerTask - The task that is to be cancelled.
      taskID - The ID assigned to the task.
    • isMainThread

      public boolean isMainThread(long threadId)
      Description copied from interface: IExecutor
      Checks if a thread is the main thread.
      Specified by:
      isMainThread in interface IExecutor
      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: IRestartable
      Handles the initialization.
      Specified by:
      initialize in interface IRestartable
    • shutDown

      public void shutDown()
      Description copied from interface: IRestartable
      Handles a shutdown.
      Specified by:
      shutDown in interface IRestartable
    • getDebugInformation

      public String getDebugInformation()
      Description copied from interface: IDebuggable
      Gets the debug information for this object.
      Specified by:
      getDebugInformation in interface IDebuggable
      Returns:
      The debug information or null if there's nothing to log at this time.