Java 类com.zaxxer.hikari.HikariPoolMXBean 实例源码

项目:psi-probe    文件:HikariCpDatasourceAccessor.java   
@Override
public DataSourceInfo getInfo(final Object resource) throws Exception {
  DataSourceInfo dataSourceInfo = null;
  if (canMap(resource)) {
    HikariDataSource source = (HikariDataSource) resource;

    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName poolName =
        new ObjectName("com.zaxxer.hikari:type=Pool (" + source.getPoolName() + ")");
    HikariPoolMXBean poolProxy =
        JMX.newMXBeanProxy(mbeanServer, poolName, HikariPoolMXBean.class);

    dataSourceInfo = new DataSourceInfo();
    dataSourceInfo.setBusyConnections(poolProxy.getActiveConnections());
    dataSourceInfo.setEstablishedConnections(poolProxy.getTotalConnections());
    dataSourceInfo.setMaxConnections(source.getMaximumPoolSize());
    dataSourceInfo.setJdbcUrl(source.getJdbcUrl());
    dataSourceInfo.setUsername(source.getUsername());
    dataSourceInfo.setResettable(false);
    dataSourceInfo.setType("hikari");
  }
  return dataSourceInfo;
}