List of usage examples for org.apache.commons.httpclient ConnectionPoolTimeoutException ConnectionPoolTimeoutException
public ConnectionPoolTimeoutException(String paramString)
From source file:com.exalead.io.failover.MonitoredHttpConnectionManager.java
/** * Try to acquire a connection from all hosts in the cluster. Loop if all hosts are down * until the timeout has expired./*from ww w . j ava 2 s .co m*/ */ private HttpConnection doGetConnection(long timeout) throws ConnectionPoolTimeoutException { // TODO: connections restriction + connections restriction timeout //int maxTotalConnections = this.params.getMaxTotalConnections(); //int maxHostConnections = maxTotalConnections; long start = System.currentTimeMillis(); boolean useTimeout = (timeout > 0); if (shutdown) { throw new IllegalStateException("Connection factory has been shutdown."); } NDC.push("acquire"); try { HttpConnection connection = null; int loops = 0; while (true) { loops++; if (loops > failMaxTries) { throw new ConnectionPoolTimeoutException("Could not acquire any connection (all hosts down)"); } if (loops > 1) { logger.info("Restart trying to acquire on any host (loop " + loops + ")"); } try { connection = acquireConnectionOnAnyHost(); break; } catch (PoolAcquireException e) { logger.warn("All cluster hosts are down !"); if (useTimeout && (System.currentTimeMillis() - start > failTimeout)) { logger.warn("Timeout -> ConnectionPoolTimeoutException"); throw new ConnectionPoolTimeoutException( "Could not acquire any connection (all hosts down)"); } try { Thread.sleep(50); } catch (InterruptedException e2) { } } } return connection; } finally { NDC.pop(); } }