package com.codahale.metrics.httpasyncclient;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;
import static com.codahale.metrics.MetricRegistry.name;
import java.util.concurrent.TimeUnit;
import org.apache.http.config.Registry;
import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.nio.conn.ManagedNHttpClientConnection;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
import org.apache.http.nio.conn.NHttpConnectionFactory;
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
import org.apache.http.nio.reactor.ConnectingIOReactor;

public class InstrumentedNClientConnManager extends PoolingNHttpClientConnectionManager {

    public InstrumentedNClientConnManager(final ConnectingIOReactor ioreactor, final NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final MetricRegistry metricRegistry, final Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry, final long timeToLive, final TimeUnit tunit, final DnsResolver dnsResolver, final String name) {
        super(ioreactor, connFactory, iosessionFactoryRegistry, schemePortResolver, dnsResolver, timeToLive, tunit);
        metricRegistry.register(name(NHttpClientConnectionManager.class, name, "available-connections"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        // this acquires a lock on the connection pool; remove if contention sucks
                        return getTotalStats().getAvailable();
                    }
                });
        metricRegistry.register(name(NHttpClientConnectionManager.class, name, "leased-connections"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        // this acquires a lock on the connection pool; remove if contention sucks
                        return getTotalStats().getLeased();
                    }
                });
        metricRegistry.register(name(NHttpClientConnectionManager.class, name, "max-connections"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        // this acquires a lock on the connection pool; remove if contention sucks
                        return getTotalStats().getMax();
                    }
                });
        metricRegistry.register(name(NHttpClientConnectionManager.class, name, "pending-connections"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        // this acquires a lock on the connection pool; remove if contention sucks
                        return getTotalStats().getPending();
                    }
                });
    }

}

@@ -1427,36 +1427,33 @@
                 
-new 
+(
 Gauge%3CInteger%3E()
@@ -1454,95 +1454,18 @@
 ger%3E
-(
 ) 
-%7B%0A                    @Override%0A                    public Integer getValue() %7B%0A    
+() -%3E %7B%0A
     
@@ -1567,36 +1567,32 @@
                 
-    
 return getTotalS
@@ -1614,38 +1614,16 @@
 able();%0A
-                    %7D%0A
         
@@ -1744,36 +1744,33 @@
                 
-new 
+(
 Gauge%3CInteger%3E()
@@ -1771,95 +1771,18 @@
 ger%3E
-(
 ) 
-%7B%0A                    @Override%0A                    public Integer getValue() %7B%0A    
+() -%3E %7B%0A
     
@@ -1884,36 +1884,32 @@
                 
-    
 return getTotalS
@@ -1928,38 +1928,16 @@
 ased();%0A
-                    %7D%0A
         
@@ -2055,36 +2055,33 @@
                 
-new 
+(
 Gauge%3CInteger%3E()
@@ -2082,95 +2082,18 @@
 ger%3E
-(
 ) 
-%7B%0A                    @Override%0A                    public Integer getValue() %7B%0A    
+() -%3E %7B%0A
     
@@ -2195,36 +2195,32 @@
                 
-    
 return getTotalS
@@ -2236,38 +2236,16 @@
 tMax();%0A
-                    %7D%0A
         
@@ -2379,12 +2379,9 @@
     
-new 
+(
 Gaug
@@ -2394,95 +2394,18 @@
 ger%3E
-(
 ) 
-%7B%0A                    @Override%0A                    public Integer getValue() %7B%0A    
+() -%3E %7B%0A
     
@@ -2507,36 +2507,32 @@
                 
-    
 return getTotalS
@@ -2556,30 +2556,8 @@
 ();%0A
-                    %7D%0A
     

Use lambdas in metrics-asynchttpclient for gauges