List of usage examples for org.apache.http.impl.conn.tsccm RouteSpecificPool dropEntry
public void dropEntry()
From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java
@Override public void freeEntry(final BasicPoolEntry entry, final boolean reusable, final long validDuration, final TimeUnit timeUnit) { final HttpRoute route = entry.getPlannedRoute(); if (log.isDebugEnabled()) { log.debug("Releasing connection" + " [" + route + "][" + entry.getState() + "]"); }/*from w w w . j a va 2 s .c om*/ poolLock.lock(); try { if (shutdown) { // the pool is shut down, release the // connection's resources and get out of here closeConnection(entry); return; } // no longer issued, we keep a hard reference now leasedConnections.remove(entry); final RouteSpecificPool rospl = getRoutePool(route, true); if (reusable && rospl.getCapacity() >= 0) { if (log.isDebugEnabled()) { final String s; if (validDuration > 0) { s = "for " + validDuration + " " + timeUnit; } else { s = "indefinitely"; } log.debug("Pooling connection" + " [" + route + "][" + entry.getState() + "]; keep alive " + s); } rospl.freeEntry(entry); entry.updateExpiry(validDuration, timeUnit); freeConnections.add(entry); } else { closeConnection(entry); rospl.dropEntry(); numConnections--; } notifyWaitingThread(rospl); } finally { poolLock.unlock(); } }
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 *///from w w w . j a v a2 s . c o m 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; }
From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java
@Override protected void handleLostEntry(final HttpRoute route) { poolLock.lock();//from w ww . j ava 2 s .c o m try { final RouteSpecificPool rospl = getRoutePool(route, true); rospl.dropEntry(); if (rospl.isUnused()) { routeToPool.remove(route); } numConnections--; notifyWaitingThread(rospl); } finally { poolLock.unlock(); } }