hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Setting different socket timeouts to connections obtained from a pool
Date Thu, 14 Feb 2013 15:33:40 GMT
On Thu, 2013-02-14 at 16:11 +0530, Asankha C. Perera wrote:
> Hi All
> 
> I was trying to use a custom connection pool implementation extending 
> the BasicNIOConnPool for sending messages. My use case requires me to 
> use different socket timeouts for different requests. When I want to 
> send out messages, I do something like the following (code simplified 
> for illustration)
> 
>          final BasicHttpContext coreContext = new BasicHttpContext();
>          coreContext.setAttribute("timeout", 3000);
>          asyncRequester.execute(requestProducer, responseConsumer, 
> connectionPool, coreContext);
> 
> 
> My connection pool overrides the requestCompleted() method, and tries to 
> read the socket timeout I had set earlier
> 
> public class UltraNIOConnPool extends BasicNIOConnPool {
>      protected void requestCompleted(SessionRequest request) {
>          super.requestCompleted(request);
>          Integer timeout = (Integer) 
> request.getSession().getAttribute("timeout");
>          if (timeout != null) {
>              NHttpClientConnection conn = (NHttpClientConnection) 
> request.getSession().getAttribute(ExecutionContext.HTTP_CONNECTION);
>              conn.setSocketTimeout(timeout);
>          }
>      }
> }
> 
> However, the values I put into the coreContext above is not available in 
> the session within the requestCompleted(). I need to set the socket 
> timeout before the new connection is used. I am quite sure I am 
> overlooking something simpler.. so any help is very much appreciated
> 
> regards
> asankha
> 

Asankha

A custom request interceptor should be a better place to do so. The
request interceptor will give you access to the right execution context
containing your custom attribute(s).

Hope this helps

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message