I've been a user of HttpClient 3 for several years and am now migrating to 
using HttpClient 4.

With version 3, I wrapped (extended) the client in order to instrument it (via 
JMX).  I kept track of the following pieces of information, per host:
-Number of request (socket) timeouts
-Number of connection timeouts
-Number of timeouts while waiting for connection from pool
-Total number of requests
-Average Request duration
-Maximum Request duration
-Number of connections currently in pool
-Max connections in pool

With HttpClient version 4, I'd rather not extend the client and would instead 
like have developers use a pre-configured httpclient that was created with a 
ThreadSafeClientConnManager.

I can see how to use a HttpRequestInterceptor and HttpResponseInterceptor
to record things like number of transactions, request durations, etc.

What I need help with is determining how I can record timeout information.  
When I'd recorded this in the past, I caught exceptions thrown by HttpClient's 
execute method in my extended class.  It looks like when I call execute on 
HttpClient 4, if an exception is thrown, the HttpResponseInterceptor will not 
be called.  I'm not sure where to intercept in this case.

Another related question: I typically have a scheduled task that occasionally 
calls the connection manager's closeIdleConnections method.  After I do this, 
when I want to learn how many connections are in each pool, I have to have kept 
track of each HttpRoute and then call the getConnectionsInPool(route) method 
for each route.  Is there a way I can have the connection manager give me the 
list of routes so I don't have to keep track of them myself?

And one final question: I'd like to consider the possibility of handing out an 
HttpClient that will not talk to any host unless it has been explicitly 
configured (to force developers to think about the proper max pool size so we 
fail fast when a remote source is having issues).  What I'm thinking is 
something like:
 ConnPerRouteBean connPerRoute = new ConnPerRouteBean(0);

 // Then explicitly enable hosts as follows
 HttpHost localhost = new HttpHost("localhost", 8080);
 localhostRoute = new HttpRoute(localhost);
 connPerRoute.setMaxForRoute(localhostRoute, 10);
 ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);

But I currently get an exception when instantiating ConnPerRouteBean with 0 
(needs to be a positive integer).  Is there a different way to accomplish this 
other than the path I've outlined above?

Thanks - I realize this was long.

Mike




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to