CavalliumDBEngine/src/main/java/it/cavallium/dbengine/netty/JMXPooledNettyMonitoring.java

61 lines
1.5 KiB
Java
Raw Normal View History

2021-05-03 18:07:18 +02:00
package it.cavallium.dbengine.netty;
2021-09-17 16:56:28 +02:00
import io.net5.buffer.api.pool.BufferAllocatorMetric;
import io.net5.buffer.api.pool.PooledBufferAllocator;
import io.net5.buffer.api.pool.PooledBufferAllocatorMetricUtils;
2021-08-31 09:14:46 +02:00
import java.lang.reflect.Field;
2021-05-03 18:07:18 +02:00
public class JMXPooledNettyMonitoring extends JMXNettyMonitoring implements JMXNettyMonitoringMBean {
2021-08-31 09:14:46 +02:00
private final PooledBufferAllocator alloc;
private final BufferAllocatorMetric metric;
2021-09-09 15:30:28 +02:00
private PooledBufferAllocatorMetricUtils metricUtils;
2021-05-03 18:07:18 +02:00
2021-08-31 09:14:46 +02:00
public JMXPooledNettyMonitoring(String name, PooledBufferAllocator alloc) {
super(name, alloc.isDirectBufferPooled(), alloc.metric());
this.alloc = alloc;
this.metric = alloc.metric();
try {
2021-09-09 15:30:28 +02:00
this.metricUtils = new PooledBufferAllocatorMetricUtils(alloc);
} catch (Throwable e) {
this.metricUtils = null;
2021-08-31 09:14:46 +02:00
}
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getNumHeapArenas() {
2021-08-31 09:14:46 +02:00
return direct ? 0 : alloc.numArenas();
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getNumDirectArenas() {
2021-08-31 09:14:46 +02:00
return direct ? alloc.numArenas() : 0;
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getNumThreadLocalCachesArenas() {
2021-09-09 15:30:28 +02:00
return metricUtils != null ? metricUtils.numThreadLocalCaches() : 0;
2021-05-03 18:07:18 +02:00
}
@Deprecated
@Override
public Integer getTinyCacheSize() {
2021-08-31 09:14:46 +02:00
return 0;
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getSmallCacheSize() {
2021-09-09 15:30:28 +02:00
return metricUtils != null ? metricUtils.smallCacheSize() : 0;
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getNormalCacheSize() {
2021-09-09 15:30:28 +02:00
return metricUtils != null ? metricUtils.normalCacheSize() : 0;
2021-05-03 18:07:18 +02:00
}
@Override
public Integer getChunkSize() {
2021-09-09 15:30:28 +02:00
return metricUtils != null ? metricUtils.chunkSize() : 0;
2021-05-03 18:07:18 +02:00
}
}