Class GuiScheduler

java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.engine.GuiScheduler

public class GuiScheduler extends Object
Marshals GUI work onto the viewer's entity context using the framework scheduler. A frame is always deferred to the next tick. Repeated requests for the same Runnable are coalesced; distinct tasks share that frame. Tasks queued during a drain run on a later frame, bounding the work of even a widget whose initState requests a rebuild and then throws.
Since:
6.2.0
  • Field Details

    • context

      private final TaskContext context
    • pendingTasks

      private final Set<Runnable> pendingTasks
    • submitted

      private final Set<TaskHandle> submitted
    • frameHandle

      private TaskHandle frameHandle
    • frameScheduled

      private boolean frameScheduled
    • flushing

      private boolean flushing
    • generation

      private long generation
  • Constructor Details

    • GuiScheduler

      public GuiScheduler(@NotNull @NotNull Scheduler scheduler, @NotNull @NotNull org.bukkit.entity.Player viewer)
      Parameters:
      scheduler - the module's own injected scheduler
      viewer - the entity whose screen is being built
  • Method Details

    • isOnMainThread

      public boolean isOnMainThread()
      Returns:
      whether the caller currently owns the viewer's entity context
    • runOnMainThread

      public void runOnMainThread(@NotNull @NotNull Runnable task)
      Runs synchronously on the owning thread, otherwise submits tracked work there. A synchronous depth failure is reported and rethrown. Deferred failures are logged; JVM Errors are then rethrown unchanged to the scheduling engine.
      Parameters:
      task - the work to execute
    • scheduleFrame

      public void scheduleFrame(@NotNull @NotNull Runnable frameTask)
      Parameters:
      frameTask - the stable frame callback to enqueue, at most once per pending frame
    • schedulePendingFrame

      private void schedulePendingFrame()
    • submit

      private TaskHandle submit(Runnable task)
      Called with the queue monitor held; TaskContext.run never runs inline.
    • executeFrame

      private void executeFrame()
    • runSynchronous

      private void runSynchronous(Runnable task)
    • runDeferred

      private void runDeferred(Runnable task)
    • logFrameTaskError

      private void logFrameTaskError(Throwable failure)
    • reportRenderDepthExceeded

      private void reportRenderDepthExceeded(RenderDepthExceededException failure)
    • flush

      public void flush()
      Drains pending frame work synchronously, ignoring the normal per-frame budget (for tests).
      Throws:
      IllegalStateException - if the caller does not own the viewer's context
    • pollPending

      private Runnable pollPending()
    • cancelFrame

      private void cancelFrame()
    • cancelAll

      public void cancelAll()
      Cancels every submitted handle as well as pending frames; the scheduler may be reused afterwards.