List of usage examples for org.apache.http.impl.conn.tsccm RouteSpecificPool allocEntry
public BasicPoolEntry allocEntry(final Object state)
From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java
/** * If available, get a free pool entry for a route. * * @param rospl the route-specific pool from which to get an entry * * @return an available pool entry for the given route, or * <code>null</code> if none is available *///www. jav a2 s . com protected BasicPoolEntry getFreeEntry(final RouteSpecificPool rospl, final Object state) { BasicPoolEntry entry = null; poolLock.lock(); try { boolean done = false; while (!done) { entry = rospl.allocEntry(state); if (entry != null) { if (log.isDebugEnabled()) { log.debug("Getting free connection" + " [" + rospl.getRoute() + "][" + state + "]"); } freeConnections.remove(entry); if (entry.isExpired(System.currentTimeMillis())) { // If the free entry isn't valid anymore, get rid of it // and loop to find another one that might be valid. if (log.isDebugEnabled()) { log.debug("Closing expired free connection" + " [" + rospl.getRoute() + "][" + state + "]"); } closeConnection(entry); // We use dropEntry instead of deleteEntry because the entry // is no longer "free" (we just allocated it), and deleteEntry // can only be used to delete free entries. rospl.dropEntry(); numConnections--; } else { leasedConnections.add(entry); done = true; } } else { done = true; if (log.isDebugEnabled()) { log.debug("No free connections" + " [" + rospl.getRoute() + "][" + state + "]"); } } } } finally { poolLock.unlock(); } return entry; }