diff --git a/src/main/java/io/netty5/buffer/api/pool/MetricUtils.java b/src/main/java/io/netty5/buffer/api/pool/MetricUtils.java index 1cdb483..2e21da4 100644 --- a/src/main/java/io/netty5/buffer/api/pool/MetricUtils.java +++ b/src/main/java/io/netty5/buffer/api/pool/MetricUtils.java @@ -19,7 +19,7 @@ public class MetricUtils { MethodHandle handle = null; try { // 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 handle = lookup.findVirtual(pooledBufferClass, "arenaMetrics", MethodType.methodType(List.class)); } catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException ignored) { @@ -40,7 +40,7 @@ public class MetricUtils { // Invoke the method to get the metrics return (List) GET_ARENA_METRICS.invoke(metric); } catch (Throwable e) { - throw new RuntimeException(e); + return List.of(); } } } diff --git a/src/main/java/it/cavallium/dbengine/netty/JMXNettyMonitoringManager.java b/src/main/java/it/cavallium/dbengine/netty/JMXNettyMonitoringManager.java index a858586..fb1b878 100644 --- a/src/main/java/it/cavallium/dbengine/netty/JMXNettyMonitoringManager.java +++ b/src/main/java/it/cavallium/dbengine/netty/JMXNettyMonitoringManager.java @@ -39,20 +39,20 @@ public class JMXNettyMonitoringManager { return instance; } - public void register(String name, BufferAllocator metric) { + public void register(String name, BufferAllocator allocator) { try { name = name.replaceAll("[^\\p{IsAlphabetic}\\p{IsDigit}_]", "_"); String type; StandardMBean mbean; - if (metric instanceof PooledBufferAllocator pooledMetric) { - for (var arenaMetric : MetricUtils.getPoolArenaMetrics(pooledMetric)) { - String arenaType = pooledMetric.isDirectBufferPooled() ? "direct" : "heap"; + if (allocator instanceof PooledBufferAllocator pooledAllocator) { + for (var arenaMetric : MetricUtils.getPoolArenaMetrics(pooledAllocator)) { + String arenaType = pooledAllocator.isDirectBufferPooled() ? "direct" : "heap"; var jmx = new JMXPoolArenaNettyMonitoring(arenaMetric); mbean = new StandardMBean(jmx, JMXPoolArenaNettyMonitoringMBean.class); ObjectName botObjectName = new ObjectName("io.netty.stats:name=PoolArena,type=" + arenaType + ",arenaId=" + nextArenaId.getAndIncrement()); platformMBeanServer.registerMBean(mbean, botObjectName); } - var jmx = new JMXPooledNettyMonitoring(name, pooledMetric); + var jmx = new JMXPooledNettyMonitoring(name, pooledAllocator); type = "pooled"; mbean = new StandardMBean(jmx, JMXNettyMonitoringMBean.class);