hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asankha C. Perera" <asan...@apache.org>
Subject Setting different socket timeouts to connections obtained from a pool
Date Thu, 14 Feb 2013 10:41:26 GMT
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 C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com




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


Mime
View raw message