Class ThreadProvider

java.lang.Object
net.minestom.server.thread.ThreadProvider
Direct Known Subclasses:
PerGroupChunkProvider, PerInstanceThreadProvider, SingleThreadProvider

public abstract class ThreadProvider
extends java.lang.Object
Used to link chunks into multiple groups. Then executed into a thread pool.

You can change the current thread provider by calling UpdateManager.setThreadProvider(ThreadProvider).

  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.util.concurrent.ExecutorService pool
    The thread pool of this thread provider.
  • Constructor Summary

    Constructors 
    Constructor Description
    ThreadProvider()  
  • Method Summary

    Modifier and Type Method Description
    protected void conditionalEntityUpdate​(Instance instance, Chunk chunk, long time, EntityValidator condition)
    Executes an entity tick in an instance's chunk if condition is verified.
    int getThreadCount()
    Gets the current size of the thread pool.
    abstract void onChunkLoad​(Instance instance, int chunkX, int chunkZ)
    Called when a chunk is loaded.
    abstract void onChunkUnload​(Instance instance, int chunkX, int chunkZ)
    Called when a chunk is unloaded.
    abstract void onInstanceCreate​(Instance instance)
    Called when an Instance is registered.
    abstract void onInstanceDelete​(Instance instance)
    Called when an Instance is unregistered.
    protected void processChunkTick​(Instance instance, long chunkIndex, long time)
    Processes a whole tick for a chunk.
    void setThreadCount​(int threadCount)
    Changes the amount of threads in the thread pool.
    abstract java.util.List<java.util.concurrent.Future<?>> update​(long time)
    Performs a server tick for all chunks based on their linked thread.
    protected void updateChunk​(Instance instance, Chunk chunk, long time)
    Executes a chunk tick (blocks update).
    protected void updateCreatures​(Instance instance, Chunk chunk, long time)
    Executes an entity tick for creatures entities in an instance's chunk.
    protected void updateEntities​(Instance instance, Chunk chunk, long time)
    Executes an entity tick (all entities type creatures/objects/players) in an instance's chunk.
    protected void updateInstance​(Instance instance, long time)
    Executes an instance tick.
    protected void updateLivingEntities​(Instance instance, Chunk chunk, long time)
    Executes an entity tick for living entities in an instance's chunk.
    protected void updateObjectEntities​(Instance instance, Chunk chunk, long time)
    Executes an entity tick for object entities in an instance's chunk.
    protected void updatePlayers​(Instance instance, Chunk chunk, long time)
    Executes an entity tick for players in an instance's chunk.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • pool

      protected java.util.concurrent.ExecutorService pool
      The thread pool of this thread provider.
  • Constructor Details

  • Method Details

    • onInstanceCreate

      public abstract void onInstanceCreate​(@NotNull Instance instance)
      Called when an Instance is registered.
      Parameters:
      instance - the newly create Instance
    • onInstanceDelete

      public abstract void onInstanceDelete​(@NotNull Instance instance)
      Called when an Instance is unregistered.
      Parameters:
      instance - the deleted Instance
    • onChunkLoad

      public abstract void onChunkLoad​(@NotNull Instance instance, int chunkX, int chunkZ)
      Called when a chunk is loaded.

      Be aware that this is possible for an instance to load chunks before being registered.

      Parameters:
      instance - the instance of the chunk
      chunkX - the chunk X
      chunkZ - the chunk Z
    • onChunkUnload

      public abstract void onChunkUnload​(@NotNull Instance instance, int chunkX, int chunkZ)
      Called when a chunk is unloaded.
      Parameters:
      instance - the instance of the chunk
      chunkX - the chunk X
      chunkZ - the chunk Z
    • update

      @NotNull public abstract java.util.List<java.util.concurrent.Future<?>> update​(long time)
      Performs a server tick for all chunks based on their linked thread.
      Parameters:
      time - the update time in milliseconds
      Returns:
      the futures to execute to complete the tick
    • getThreadCount

      public int getThreadCount()
      Gets the current size of the thread pool.
      Returns:
      the thread pool's size
    • setThreadCount

      public void setThreadCount​(int threadCount)
      Changes the amount of threads in the thread pool.
      Parameters:
      threadCount - the new amount of threads
    • processChunkTick

      protected void processChunkTick​(@NotNull Instance instance, long chunkIndex, long time)
      Processes a whole tick for a chunk.
      Parameters:
      instance - the instance of the chunk
      chunkIndex - the index of the chunk ChunkUtils.getChunkIndex(int, int)
      time - the time of the update in milliseconds
    • updateInstance

      protected void updateInstance​(@NotNull Instance instance, long time)
      Executes an instance tick.
      Parameters:
      instance - the instance
      time - the current time in ms
    • updateChunk

      protected void updateChunk​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes a chunk tick (blocks update).
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • updateEntities

      protected void updateEntities​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes an entity tick (all entities type creatures/objects/players) in an instance's chunk.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • updateObjectEntities

      protected void updateObjectEntities​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes an entity tick for object entities in an instance's chunk.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • updateLivingEntities

      protected void updateLivingEntities​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes an entity tick for living entities in an instance's chunk.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • updateCreatures

      protected void updateCreatures​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes an entity tick for creatures entities in an instance's chunk.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • updatePlayers

      protected void updatePlayers​(@NotNull Instance instance, @NotNull Chunk chunk, long time)
      Executes an entity tick for players in an instance's chunk.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
    • conditionalEntityUpdate

      protected void conditionalEntityUpdate​(@NotNull Instance instance, @NotNull Chunk chunk, long time, @Nullable EntityValidator condition)
      Executes an entity tick in an instance's chunk if condition is verified.
      Parameters:
      instance - the chunk's instance
      chunk - the chunk
      time - the current time in ms
      condition - the condition which confirm if the update happens or not