Fix refactoring

This commit is contained in:
Andrea Cavalli 2021-09-09 15:34:31 +02:00
parent 9c167a322a
commit d9fd4113e0
2 changed files with 7 additions and 7 deletions

View File

@ -19,7 +19,7 @@ public class MetricUtils {
MethodHandle handle = null; MethodHandle handle = null;
try { try {
// Find the class // Find the class
var pooledBufferClass = Class.forName("io.netty5.buffer.api.pool.PooledBufferAllocatorMetricUtils"); var pooledBufferClass = Class.forName("io.netty5.buffer.api.pool.PooledBufferAllocatorMetric");
// Find the handle of the method // Find the handle of the method
handle = lookup.findVirtual(pooledBufferClass, "arenaMetrics", MethodType.methodType(List.class)); handle = lookup.findVirtual(pooledBufferClass, "arenaMetrics", MethodType.methodType(List.class));
} catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException ignored) { } catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException ignored) {
@ -40,7 +40,7 @@ public class MetricUtils {
// Invoke the method to get the metrics // Invoke the method to get the metrics
return (List<PoolArenaMetric>) GET_ARENA_METRICS.invoke(metric); return (List<PoolArenaMetric>) GET_ARENA_METRICS.invoke(metric);
} catch (Throwable e) { } catch (Throwable e) {
throw new RuntimeException(e); return List.of();
} }
} }
} }

View File

@ -39,20 +39,20 @@ public class JMXNettyMonitoringManager {
return instance; return instance;
} }
public void register(String name, BufferAllocator metric) { public void register(String name, BufferAllocator allocator) {
try { try {
name = name.replaceAll("[^\\p{IsAlphabetic}\\p{IsDigit}_]", "_"); name = name.replaceAll("[^\\p{IsAlphabetic}\\p{IsDigit}_]", "_");
String type; String type;
StandardMBean mbean; StandardMBean mbean;
if (metric instanceof PooledBufferAllocator pooledMetric) { if (allocator instanceof PooledBufferAllocator pooledAllocator) {
for (var arenaMetric : MetricUtils.getPoolArenaMetrics(pooledMetric)) { for (var arenaMetric : MetricUtils.getPoolArenaMetrics(pooledAllocator)) {
String arenaType = pooledMetric.isDirectBufferPooled() ? "direct" : "heap"; String arenaType = pooledAllocator.isDirectBufferPooled() ? "direct" : "heap";
var jmx = new JMXPoolArenaNettyMonitoring(arenaMetric); var jmx = new JMXPoolArenaNettyMonitoring(arenaMetric);
mbean = new StandardMBean(jmx, JMXPoolArenaNettyMonitoringMBean.class); mbean = new StandardMBean(jmx, JMXPoolArenaNettyMonitoringMBean.class);
ObjectName botObjectName = new ObjectName("io.netty.stats:name=PoolArena,type=" + arenaType + ",arenaId=" + nextArenaId.getAndIncrement()); ObjectName botObjectName = new ObjectName("io.netty.stats:name=PoolArena,type=" + arenaType + ",arenaId=" + nextArenaId.getAndIncrement());
platformMBeanServer.registerMBean(mbean, botObjectName); platformMBeanServer.registerMBean(mbean, botObjectName);
} }
var jmx = new JMXPooledNettyMonitoring(name, pooledMetric); var jmx = new JMXPooledNettyMonitoring(name, pooledAllocator);
type = "pooled"; type = "pooled";
mbean = new StandardMBean(jmx, JMXNettyMonitoringMBean.class); mbean = new StandardMBean(jmx, JMXNettyMonitoringMBean.class);