MinecraftServerStatistics.java
net.minecraft.util.monitoring.jmx.MinecraftServerStatistics
信息
- 全限定名:net.minecraft.util.monitoring.jmx.MinecraftServerStatistics
- 类型:public final class
- 包:net.minecraft.util.monitoring.jmx
- 源码路径:src/main/java/net/minecraft/util/monitoring/jmx/MinecraftServerStatistics.java
- 起始行号:L28
- 实现:DynamicMBean
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
server- 类型:
MinecraftServer - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
mBeanInfo- 类型:
MBeanInfo - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
attributeDescriptionByName- 类型:
Map<String,MinecraftServerStatistics.AttributeDescription> - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.util.monitoring.jmx.MinecraftServerStatistics.AttributeDescription- 类型:
class - 修饰符:
private static final - 源码定位:
L101 - 说明:
TODO
- 类型:
构造器
private MinecraftServerStatistics(MinecraftServer server) @ L38
- 构造器名:MinecraftServerStatistics
- 源码定位:L38
- 修饰符:private
参数:
- server: MinecraftServer
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static void registerJmxMonitoring(MinecraftServer server) @ L50
- 方法名:registerJmxMonitoring
- 源码定位:L50
- 返回类型:void
- 修饰符:public static
参数:
- server: MinecraftServer
说明:
TODO
private float getAverageTickTime() @ L58
- 方法名:getAverageTickTime
- 源码定位:L58
- 返回类型:float
- 修饰符:private
参数:
- 无
说明:
TODO
private long[] getTickTimes() @ L62
- 方法名:getTickTimes
- 源码定位:L62
- 返回类型:long[]
- 修饰符:private
参数:
- 无
说明:
TODO
public Object getAttribute(String attribute) @ L66
- 方法名:getAttribute
- 源码定位:L66
- 返回类型:Object
- 修饰符:public
参数:
- attribute: String
说明:
TODO
public void setAttribute(Attribute attribute) @ L72
- 方法名:setAttribute
- 源码定位:L72
- 返回类型:void
- 修饰符:public
参数:
- attribute: Attribute
说明:
TODO
public AttributeList getAttributes(String[] attributes) @ L76
- 方法名:getAttributes
- 源码定位:L76
- 返回类型:AttributeList
- 修饰符:public
参数:
- attributes: String[]
说明:
TODO
public AttributeList setAttributes(AttributeList attributes) @ L86
- 方法名:setAttributes
- 源码定位:L86
- 返回类型:AttributeList
- 修饰符:public
参数:
- attributes: AttributeList
说明:
TODO
public Object invoke(String actionName, Object[] params, String[] signature) @ L91
- 方法名:invoke
- 源码定位:L91
- 返回类型:Object
- 修饰符:public
参数:
- actionName: String
- params: Object[]
- signature: String[]
说明:
TODO
public MBeanInfo getMBeanInfo() @ L96
- 方法名:getMBeanInfo
- 源码定位:L96
- 返回类型:MBeanInfo
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public final class MinecraftServerStatistics implements DynamicMBean {
private static final Logger LOGGER = LogUtils.getLogger();
private final MinecraftServer server;
private final MBeanInfo mBeanInfo;
private final Map<String, MinecraftServerStatistics.AttributeDescription> attributeDescriptionByName = Stream.of(
new MinecraftServerStatistics.AttributeDescription("tickTimes", this::getTickTimes, "Historical tick times (ms)", long[].class),
new MinecraftServerStatistics.AttributeDescription("averageTickTime", this::getAverageTickTime, "Current average tick time (ms)", long.class)
)
.collect(Collectors.toMap(attributeDescription -> attributeDescription.name, Function.identity()));
private MinecraftServerStatistics(MinecraftServer server) {
this.server = server;
MBeanAttributeInfo[] mBeanAttributeInfos = this.attributeDescriptionByName
.values()
.stream()
.map(MinecraftServerStatistics.AttributeDescription::asMBeanAttributeInfo)
.toArray(MBeanAttributeInfo[]::new);
this.mBeanInfo = new MBeanInfo(
MinecraftServerStatistics.class.getSimpleName(), "metrics for dedicated server", mBeanAttributeInfos, null, null, new MBeanNotificationInfo[0]
);
}
public static void registerJmxMonitoring(MinecraftServer server) {
try {
ManagementFactory.getPlatformMBeanServer().registerMBean(new MinecraftServerStatistics(server), new ObjectName("net.minecraft.server:type=Server"));
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException var2) {
LOGGER.warn("Failed to initialise server as JMX bean", (Throwable)var2);
}
}
private float getAverageTickTime() {
return this.server.getCurrentSmoothedTickTime();
}
private long[] getTickTimes() {
return this.server.getTickTimesNanos();
}
@Override
public @Nullable Object getAttribute(String attribute) {
MinecraftServerStatistics.AttributeDescription attributeDescription = this.attributeDescriptionByName.get(attribute);
return attributeDescription == null ? null : attributeDescription.getter.get();
}
@Override
public void setAttribute(Attribute attribute) {
}
@Override
public AttributeList getAttributes(String[] attributes) {
List<Attribute> attributeList = Arrays.stream(attributes)
.map(this.attributeDescriptionByName::get)
.filter(Objects::nonNull)
.map(attributeDescription -> new Attribute(attributeDescription.name, attributeDescription.getter.get()))
.collect(Collectors.toList());
return new AttributeList(attributeList);
}
@Override
public AttributeList setAttributes(AttributeList attributes) {
return new AttributeList();
}
@Override
public @Nullable Object invoke(String actionName, Object[] params, String[] signature) {
return null;
}
@Override
public MBeanInfo getMBeanInfo() {
return this.mBeanInfo;
}
private static final class AttributeDescription {
private final String name;
private final Supplier<Object> getter;
private final String description;
private final Class<?> type;
private AttributeDescription(String name, Supplier<Object> getter, String description, Class<?> type) {
this.name = name;
this.getter = getter;
this.description = description;
this.type = type;
}
private MBeanAttributeInfo asMBeanAttributeInfo() {
return new MBeanAttributeInfo(this.name, this.type.getSimpleName(), this.description, true, false, false);
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
Attribute()
- 引用位置: