Ethan Leroy
Ethan Leroy

Reputation: 16544

Monitor connection pool of PoolingHttpClientConnectionManager

I'd like to monitor the connection pool of a Apache httpComponents PoolingHttpClientConnectionManager but cannot find a way to access it.

We create our HttpClient using the following builder:

HttpClient httpClient = HttpClientBuilder.create()
            .setMaxConnTotal(maxConnections)
            .setMaxConnPerRoute(maxConnectionsPerRoute)
            .build();

This creates an instance of an InternalHttpClient, which holds an instance of a PoolingHttpClientConnectionManager, which holds an instance of a CPool.

CPool would give us access to T getRoutes() and PoolStats getStats(T) — which looks promising to me. But I can't really find out how to get access to this CPool.

HttpClient.getConnectionManager() is deprecated. InternalHttpClient.getConnectionManager() is not deprecated, but returns a custom connection manager, which only exposes some of the methods of the real connection manager instance behind it.

So, how to get access to these stats? These would be very helpful for us.

Upvotes: 4

Views: 4013

Answers (1)

ok2c
ok2c

Reputation: 27538

Use ConnPoolControl implemented by PoolingHttpClientConnectionManager

PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
ConnPoolControl<HttpRoute> connPoolControl = cm;
CloseableHttpClient client = HttpClients.custom()
        .setConnectionManager(cm)
        .build();

Upvotes: 3

Related Questions