SuppressedExceptionCollector.java
net.minecraft.server.SuppressedExceptionCollector
信息
- 全限定名:net.minecraft.server.SuppressedExceptionCollector
- 类型:public class
- 包:net.minecraft.server
- 源码路径:src/main/java/net/minecraft/server/SuppressedExceptionCollector.java
- 起始行号:L9
- 职责:
TODO
字段/常量
-
LATEST_ENTRY_COUNT- 类型:
int - 修饰符:
private static final - 源码定位:
L10 - 说明:
TODO
- 类型:
-
latestEntries- 类型:
Queue<SuppressedExceptionCollector.LongEntry> - 修饰符:
private final - 源码定位:
L11 - 说明:
TODO
- 类型:
-
entryCounts- 类型:
Object2IntLinkedOpenHashMap<SuppressedExceptionCollector.ShortEntry> - 修饰符:
private final - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.server.SuppressedExceptionCollector.LongEntry- 类型:
record - 修饰符:
private - 源码定位:
L67 - 说明:
TODO
- 类型:
-
net.minecraft.server.SuppressedExceptionCollector.ShortEntry- 类型:
record - 修饰符:
private - 源码定位:
L70 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static long currentTimeMs() @ L14
- 方法名:currentTimeMs
- 源码定位:L14
- 返回类型:long
- 修饰符:private static
参数:
- 无
说明:
TODO
public synchronized void addEntry(String location, Throwable throwable) @ L18
- 方法名:addEntry
- 源码定位:L18
- 返回类型:void
- 修饰符:public synchronized
参数:
- location: String
- throwable: Throwable
说明:
TODO
public synchronized String dump() @ L32
- 方法名:dump
- 源码定位:L32
- 返回类型:String
- 修饰符:public synchronized
参数:
- 无
说明:
TODO
代码
public class SuppressedExceptionCollector {
private static final int LATEST_ENTRY_COUNT = 8;
private final Queue<SuppressedExceptionCollector.LongEntry> latestEntries = new ArrayListDeque<>();
private final Object2IntLinkedOpenHashMap<SuppressedExceptionCollector.ShortEntry> entryCounts = new Object2IntLinkedOpenHashMap<>();
private static long currentTimeMs() {
return System.currentTimeMillis();
}
public synchronized void addEntry(String location, Throwable throwable) {
long now = currentTimeMs();
String message = throwable.getMessage();
this.latestEntries.add(new SuppressedExceptionCollector.LongEntry(now, location, (Class<? extends Throwable>)throwable.getClass(), message));
while (this.latestEntries.size() > 8) {
this.latestEntries.remove();
}
SuppressedExceptionCollector.ShortEntry key = new SuppressedExceptionCollector.ShortEntry(location, (Class<? extends Throwable>)throwable.getClass());
int currentValue = this.entryCounts.getInt(key);
this.entryCounts.putAndMoveToFirst(key, currentValue + 1);
}
public synchronized String dump() {
long current = currentTimeMs();
StringBuilder result = new StringBuilder();
if (!this.latestEntries.isEmpty()) {
result.append("\n\t\tLatest entries:\n");
for (SuppressedExceptionCollector.LongEntry e : this.latestEntries) {
result.append("\t\t\t")
.append(e.location)
.append(":")
.append(e.cls)
.append(": ")
.append(e.message)
.append(" (")
.append(current - e.timestampMs)
.append("ms ago)")
.append("\n");
}
}
if (!this.entryCounts.isEmpty()) {
if (result.isEmpty()) {
result.append("\n");
}
result.append("\t\tEntry counts:\n");
for (Entry<SuppressedExceptionCollector.ShortEntry> e : Object2IntMaps.fastIterable(this.entryCounts)) {
result.append("\t\t\t").append(e.getKey().location).append(":").append(e.getKey().cls).append(" x ").append(e.getIntValue()).append("\n");
}
}
return result.isEmpty() ? "~~NONE~~" : result.toString();
}
private record LongEntry(long timestampMs, String location, Class<? extends Throwable> cls, String message) {
}
private record ShortEntry(String location, Class<? extends Throwable> cls) {
}
}引用的其他类
- LoggedChatMessage
- 引用位置:
方法调用 - 关联成员:
System.currentTimeMillis()
- 引用位置: