Source:
<code>public BlockingChannelInfo(ConnectionPoolConfig config, String host, int port, MetricRegistry registry) { this.config = config; this.blockingChannelAvailableConnections = new ArrayBlockingQueue<BlockingChannel>(config.connectionPoolMaxConnectionsPerHost); this.blockingChannelActiveConnections = new ArrayBlockingQueue<BlockingChannel>(config.connectionPoolMaxConnectionsPerHost); this.numberOfConnections = new AtomicInteger(0); this.rwlock = new ReentrantReadWriteLock(); this.lock = new Object(); this.host = host; this.port = port; this.registry = registry; this.name = host + ":" + port; availableConnections = new Gauge<Integer>() { @Override public Integer getValue() { return blockingChannelAvailableConnections.size(); } }; <START> registry <END> .register(MetricRegistry.name(BlockingChannelInfo.class, name + "availableConnections"), availableConnections); activeConnections = new Gauge<Integer>() { @Override public Integer getValue() { return blockingChannelActiveConnections.size(); } }; registry.register(MetricRegistry.name(BlockingChannelInfo.class, name + "activeConnections"), activeConnections); totalNumberOfConnections = new Gauge<Integer>() { @Override public Integer getValue() { return numberOfConnections.intValue(); } }; registry.register(MetricRegistry.name(BlockingChannelInfo.class, name + "totalNumberOfConnections"), totalNumberOfConnections); logger.info("Starting blocking channel info for host and port {}", host, port); }</code><technical_language>BlockingChannelInfo is constructed on-demand (as connections established). on-demand registration of metrics interact sensors metric registered time sensor invokes setMbeanQuery. I concerned metrics end exposed of on-demand construction/registration. verified jconsole</technical_language>

Target:
public BlockingChannelInfo(ConnectionPoolConfig config, String host, int port, MetricRegistry registry) { this.config = config; this.blockingChannelAvailableConnections = new ArrayBlockingQueue<BlockingChannel>(config.connectionPoolMaxConnectionsPerHost); this.blockingChannelActiveConnections = new ArrayBlockingQueue<BlockingChannel>(config.connectionPoolMaxConnectionsPerHost); this.numberOfConnections = new AtomicInteger(0); this.rwlock = new ReentrantReadWriteLock(); this.lock = new Object(); this.host = host; this.port = port; this.name = host + ":" + port; availableConnections = new Gauge<Integer>() { @Override public Integer getValue() { return blockingChannelAvailableConnections.size(); } }; registry .register(MetricRegistry.name(BlockingChannelInfo.class, name + "-availableConnections"), availableConnections); activeConnections = new Gauge<Integer>() { @Override public Integer getValue() { return blockingChannelActiveConnections.size(); } }; registry.register(MetricRegistry.name(BlockingChannelInfo.class, name + "-activeConnections"), activeConnections); totalNumberOfConnections = new Gauge<Integer>() { @Override public Integer getValue() { return numberOfConnections.intValue(); } }; registry.register(MetricRegistry.name(BlockingChannelInfo.class, name + "-totalNumberOfConnections"), totalNumberOfConnections); logger.info("Starting blocking channel info for host and port {}", host, port); }