Interface RegionizedScheduler


public interface RegionizedScheduler
Schedules tasks to run on the region thread that owns a given world position.

The server world is split into independently-ticked regions, each owned by a single worker thread. Tasks submitted through this scheduler run on whichever thread currently owns the targeted (worldName, pos), rather than on the calling thread.

Region threads must never block. Long work belongs on an executor of your own, whose result is then handed back to the right region with execute(Key, ChunkPos, Runnable).

Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    execute(Key worldName, ChunkPos pos, Runnable task)
    Schedules task to run as soon as possible on the region thread owning pos.
    boolean
    executeDelayed(Key worldName, ChunkPos pos, Runnable task, long delayTicks)
    Schedules task to run on the region thread owning pos, after at least delayTicks server ticks have elapsed.
    boolean
    Checks whether the calling thread may safely touch the given position.
    List<? extends RegionTps>
    Takes a snapshot of the current per-region tick performance.
  • Method Details

    • execute

      boolean execute(Key worldName, ChunkPos pos, Runnable task)
      Schedules task to run as soon as possible on the region thread owning pos.
      Parameters:
      worldName - the key of the world the position belongs to
      pos - the chunk position identifying the target region
      task - the task to run
      Returns:
      false if the task failed to be scheduled
      Since:
      0.1.0
    • executeDelayed

      boolean executeDelayed(Key worldName, ChunkPos pos, Runnable task, long delayTicks)
      Schedules task to run on the region thread owning pos, after at least delayTicks server ticks have elapsed.
      Parameters:
      worldName - the key of the world the position belongs to
      pos - the chunk position identifying the target region
      task - the task to run
      delayTicks - the minimum number of ticks to wait before running the task
      Returns:
      false if the task failed to be scheduled
      Since:
      0.1.0
    • isOwnedByCurrentThread

      boolean isOwnedByCurrentThread(Key worldName, ChunkPos pos)
      Checks whether the calling thread may safely touch the given position.
      Parameters:
      worldName - the key of the world the position belongs to
      pos - the chunk position identifying the target region
      Returns:
      true if the calling thread is the region thread that currently owns pos
      Since:
      0.1.0
    • tpsSnapshots

      List<? extends RegionTps> tpsSnapshots()
      Takes a snapshot of the current per-region tick performance.
      Returns:
      the tick performance of every currently active region, ordered by ascending TPS (worst-performing regions first)
      Since:
      0.1.0