Class Context

java.lang.Object
com.ultikits.ultitools.scheduling.internal.Context
All Implemented Interfaces:
TaskContext, Executor

@Internal final class Context extends Object implements TaskContext
Validates submissions and maps an affinity to one backend delivery.
  • Field Details

    • owner

      final OwnedScheduler owner
    • affinity

      private final Context.Affinity affinity
    • world

      @Nullable private final @Nullable org.bukkit.World world
    • chunkX

      private final int chunkX
    • chunkZ

      private final int chunkZ
    • entity

      @Nullable private final @Nullable org.bukkit.entity.Entity entity
  • Constructor Details

    • Context

      Context(OwnedScheduler owner, Context.Affinity affinity, @Nullable @Nullable org.bukkit.World world, int chunkX, int chunkZ, @Nullable @Nullable org.bukkit.entity.Entity entity)
  • Method Details

    • run

      public TaskHandle run(Runnable task)
      Description copied from interface: TaskContext
      Runs once, never inline, even on the context's own thread; on tick contexts, on the next tick. A thrown failure is logged exactly once at WARNING with the owner's name and original throwable; the handle ends TaskState.FAILED and its completion fails with that throwable.
      Specified by:
      run in interface TaskContext
    • runLater

      public TaskHandle runLater(Duration delay, Runnable task)
      Description copied from interface: TaskContext
      Runs once after a delay. Zero behaves as TaskContext.run(Runnable). Failure logging and exceptional completion are the same as for run.
      Specified by:
      runLater in interface TaskContext
    • runRepeating

      public TaskHandle runRepeating(Duration initialDelay, Duration period, Consumer<? super TaskHandle> task)
      Description copied from interface: TaskContext
      Runs after the initial delay and then at the given period until cancelled, retired or unloaded. The consumer receives its own handle and may cancel itself. An exception from one execution is logged with the owner's name and does not stop repetition.
      Specified by:
      runRepeating in interface TaskContext
    • supply

      public <T> CompletableFuture<T> supply(Supplier<? extends T> task)
      Description copied from interface: TaskContext
      Runs task once (as TaskContext.run(Runnable)) and completes the returned future with its result, or exceptionally with what it threw, without logging the failure while the future can still observe it. The future follows CompletableFuture rules: cancelling it before it completes always succeeds. If the task has not started it then never runs; if it has started it finishes, its result is discarded, and an exception it throws is logged once as a WARNING with the owner's name, because no caller can observe it any more. An entity removed before the start completes the future with TaskRetiredException.
      Specified by:
      supply in interface TaskContext
    • execute

      public void execute(Runnable command)
      Description copied from interface: TaskContext
      Runs the command through TaskContext.run(Runnable), discarding its handle. A thrown failure is logged exactly once at WARNING with the owner's name and original throwable.
      Specified by:
      execute in interface Executor
      Specified by:
      execute in interface TaskContext
    • isCurrentThread

      public boolean isCurrentThread()
      Description copied from interface: TaskContext
      Whether the calling thread owns this context right now, whether or not it is running inside a task submitted through this API.

      On Paper every tick context (global, every region, every entity) is owned by the server main thread, so code on the main thread (an event listener, a command, a task) gets true and every other thread gets false. Under Folia the answer follows region ownership. The async context is owned by no thread and always answers false; to check that the caller is off the tick threads use !scheduler.global().isCurrentThread(). For an entity that is already removed the answer is unspecified.

      Specified by:
      isCurrentThread in interface TaskContext
    • deliver

      @Nullable @Nullable io.papermc.paper.threadedregions.scheduler.ScheduledTask deliver(Consumer<io.papermc.paper.threadedregions.scheduler.ScheduledTask> task, Runnable retired, long delay)
    • convert

      private long convert(Duration duration)