Package net.minestom.server.thread
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 anInstance
is registered.abstract void
onInstanceDelete(Instance instance)
Called when anInstance
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.
-
Field Details
-
pool
protected java.util.concurrent.ExecutorService poolThe thread pool of this thread provider.
-
-
Constructor Details
-
ThreadProvider
public ThreadProvider()
-
-
Method Details
-
onInstanceCreate
Called when anInstance
is registered.- Parameters:
instance
- the newly createInstance
-
onInstanceDelete
Called when anInstance
is unregistered.- Parameters:
instance
- the deletedInstance
-
onChunkLoad
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 chunkchunkX
- the chunk XchunkZ
- the chunk Z
-
onChunkUnload
Called when a chunk is unloaded.- Parameters:
instance
- the instance of the chunkchunkX
- the chunk XchunkZ
- 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
Processes a whole tick for a chunk.- Parameters:
instance
- the instance of the chunkchunkIndex
- the index of the chunkChunkUtils.getChunkIndex(int, int)
time
- the time of the update in milliseconds
-
updateInstance
Executes an instance tick.- Parameters:
instance
- the instancetime
- the current time in ms
-
updateChunk
Executes a chunk tick (blocks update).- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- the current time in ms
-
updateEntities
Executes an entity tick (all entities type creatures/objects/players) in an instance's chunk.- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- the current time in ms
-
updateObjectEntities
Executes an entity tick for object entities in an instance's chunk.- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- the current time in ms
-
updateLivingEntities
Executes an entity tick for living entities in an instance's chunk.- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- the current time in ms
-
updateCreatures
Executes an entity tick for creatures entities in an instance's chunk.- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- the current time in ms
-
updatePlayers
Executes an entity tick for players in an instance's chunk.- Parameters:
instance
- the chunk's instancechunk
- the chunktime
- 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 instancechunk
- the chunktime
- the current time in mscondition
- the condition which confirm if the update happens or not
-