package com.yammer.metrics.httpclient;

import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.MetricsRegistry;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.SchemeRegistryFactory;

import java.util.concurrent.TimeUnit;

/**
 * A {@link ClientConnectionManager} which monitors the number of open connections.
 */
public class InstrumentedClientConnManager extends PoolingClientConnectionManager {
    public InstrumentedClientConnManager() {
        this(SchemeRegistryFactory.createDefault());
    }

    public InstrumentedClientConnManager(SchemeRegistry registry) {
        this(registry, -1, TimeUnit.MILLISECONDS);
    }

    public InstrumentedClientConnManager(SchemeRegistry registry,
                                         long connTTL,
                                         TimeUnit connTTLTimeUnit) {
        this(Metrics.defaultRegistry(), registry, connTTL, connTTLTimeUnit);
    }

    public InstrumentedClientConnManager(MetricsRegistry metricsRegistry,
                                         SchemeRegistry registry,
                                         long connTTL,
                                         TimeUnit connTTLTimeUnit) {
        super(registry, connTTL, connTTLTimeUnit);
        metricsRegistry.newGauge(ClientConnectionManager.class,
                                 "available-connections",
                                 new Gauge<Integer>() {
                                     @Override
                                     public Integer value() {
                                         // this acquires a lock on the connection pool; remove if contention sucks
                                         return getTotalStats().getAvailable();
                                     }
                                 });
        metricsRegistry.newGauge(ClientConnectionManager.class,
                                 "leased-connections",
                                 new Gauge<Integer>() {
                                     @Override
                                     public Integer value() {
                                         // this acquires a lock on the connection pool; remove if contention sucks
                                         return getTotalStats().getLeased();
                                     }
                                 });
        metricsRegistry.newGauge(ClientConnectionManager.class,
                                 "max-connections",
                                 new Gauge<Integer>() {
                                     @Override
                                     public Integer value() {
                                         // this acquires a lock on the connection pool; remove if contention sucks
                                         return getTotalStats().getMax();
                                     }
                                 });
        metricsRegistry.newGauge(ClientConnectionManager.class,
                                 "pending-connections",
                                 new Gauge<Integer>() {
                                     @Override
                                     public Integer value() {
                                         // this acquires a lock on the connection pool; remove if contention sucks
                                         return getTotalStats().getPending();
                                     }
                                 });
    }
}

@@ -199,32 +199,73 @@
 nectionManager;%0A
+import org.apache.http.conn.DnsResolver;%0A
 import org.apach
@@ -419,16 +419,75 @@
 Factory;
+%0Aimport org.apache.http.impl.conn.SystemDefaultDnsResolver;
 %0A%0Aimport
@@ -1476,15 +1476,463 @@
     
-super(r
+this(metricsRegistry, registry, connTTL, connTTLTimeUnit, new SystemDefaultDnsResolver());%0A    %7D%0A%0A    public InstrumentedClientConnManager(MetricsRegistry metricsRegistry,%0A                                         SchemeRegistry schemeRegistry,%0A                                         long connTTL,%0A                                         TimeUnit connTTLTimeUnit,%0A                                         DnsResolver dnsResolver) %7B%0A        super(schemeR
 egis
@@ -1956,24 +1956,37 @@
 nTTLTimeUnit
+, dnsResolver
 );%0A        m

Add DnsResolver param to InstrumentedClientConnManager.