ThrottlingChunkTaskDispatcher.java

net.minecraft.server.level.ThrottlingChunkTaskDispatcher

信息

  • 全限定名:net.minecraft.server.level.ThrottlingChunkTaskDispatcher
  • 类型:public class
  • 包:net.minecraft.server.level
  • 源码路径:src/main/java/net/minecraft/server/level/ThrottlingChunkTaskDispatcher.java
  • 起始行号:L12
  • 继承:ChunkTaskDispatcher
  • 职责:

    TODO

字段/常量

  • chunkPositionsInExecution

    • 类型: LongSet
    • 修饰符: private final
    • 源码定位: L13
    • 说明:

      TODO

  • maxChunksInExecution

    • 类型: int
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

  • executorSchedulerName

    • 类型: String
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ThrottlingChunkTaskDispatcher(TaskScheduler<Runnable> executor, Executor dispatcherExecutor, int maxChunksInExecution) @ L17

  • 构造器名:ThrottlingChunkTaskDispatcher
  • 源码定位:L17
  • 修饰符:public

参数:

  • executor: TaskScheduler
  • dispatcherExecutor: Executor
  • maxChunksInExecution: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void onRelease(long key) @ L23

  • 方法名:onRelease
  • 源码定位:L23
  • 返回类型:void
  • 修饰符:protected

参数:

  • key: long

说明:

TODO

protected ChunkTaskPriorityQueue.TasksForChunk popTasks() @ L28

  • 方法名:popTasks
  • 源码定位:L28
  • 返回类型:ChunkTaskPriorityQueue.TasksForChunk
  • 修饰符:protected

参数:

说明:

TODO

protected void scheduleForExecution(ChunkTaskPriorityQueue.TasksForChunk tasksForChunk) @ L33

  • 方法名:scheduleForExecution
  • 源码定位:L33
  • 返回类型:void
  • 修饰符:protected

参数:

  • tasksForChunk: ChunkTaskPriorityQueue.TasksForChunk

说明:

TODO

public String getDebugStatus() @ L39

  • 方法名:getDebugStatus
  • 源码定位:L39
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

代码

public class ThrottlingChunkTaskDispatcher extends ChunkTaskDispatcher {
    private final LongSet chunkPositionsInExecution = new LongOpenHashSet();
    private final int maxChunksInExecution;
    private final String executorSchedulerName;
 
    public ThrottlingChunkTaskDispatcher(TaskScheduler<Runnable> executor, Executor dispatcherExecutor, int maxChunksInExecution) {
        super(executor, dispatcherExecutor);
        this.maxChunksInExecution = maxChunksInExecution;
        this.executorSchedulerName = executor.name();
    }
 
    @Override
    protected void onRelease(long key) {
        this.chunkPositionsInExecution.remove(key);
    }
 
    @Override
    protected ChunkTaskPriorityQueue.@Nullable TasksForChunk popTasks() {
        return this.chunkPositionsInExecution.size() < this.maxChunksInExecution ? super.popTasks() : null;
    }
 
    @Override
    protected void scheduleForExecution(ChunkTaskPriorityQueue.TasksForChunk tasksForChunk) {
        this.chunkPositionsInExecution.add(tasksForChunk.chunkPos());
        super.scheduleForExecution(tasksForChunk);
    }
 
    @VisibleForTesting
    public String getDebugStatus() {
        return this.executorSchedulerName
            + "=["
            + this.chunkPositionsInExecution.longStream().mapToObj(key -> key + ":" + ChunkPos.unpack(key)).collect(Collectors.joining(","))
            + "], s="
            + this.sleeping;
    }
}

引用的其他类