List of usage examples for org.apache.http.impl.conn.tsccm BasicPoolEntry getPlannedRoute
protected final HttpRoute getPlannedRoute()
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() + "]"); }// w ww . j a va2s.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
/** * Deletes a given pool entry.//from ww w . j a va 2 s . c om * This closes the pooled connection and removes all references, * so that it can be GCed. * * <p><b>Note:</b> Does not remove the entry from the freeConnections list. * It is assumed that the caller has already handled this step.</p> * <!-- @@@ is that a good idea? or rather fix it? --> * * @param entry the pool entry for the connection to delete */ protected void deleteEntry(final BasicPoolEntry entry) { final HttpRoute route = entry.getPlannedRoute(); if (log.isDebugEnabled()) { log.debug("Deleting connection" + " [" + route + "][" + entry.getState() + "]"); } poolLock.lock(); try { closeConnection(entry); final RouteSpecificPool rospl = getRoutePool(route, true); rospl.deleteEntry(entry); numConnections--; if (rospl.isUnused()) { routeToPool.remove(route); } } finally { poolLock.unlock(); } }
From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java
@Override public void shutdown() { poolLock.lock();/*from w w w. jav a2 s . c o m*/ try { if (shutdown) { return; } shutdown = true; // close all connections that are issued to an application final Iterator<BasicPoolEntry> iter1 = leasedConnections.iterator(); while (iter1.hasNext()) { final BasicPoolEntry entry = iter1.next(); iter1.remove(); closeConnection(entry); } // close all free connections final Iterator<BasicPoolEntry> iter2 = freeConnections.iterator(); while (iter2.hasNext()) { final BasicPoolEntry entry = iter2.next(); iter2.remove(); if (log.isDebugEnabled()) { log.debug( "Closing connection" + " [" + entry.getPlannedRoute() + "][" + entry.getState() + "]"); } closeConnection(entry); } // wake up all waiting threads final Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { final WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
From source file:org.apache.http.impl.conn.tsccm.RouteSpecificPool.java
/** * Indicates creation of an entry for this pool. * The entry will <i>not</i> be added to the list of free entries, * it is only recognized as belonging to this pool now. It can then * be passed to {@link #freeEntry freeEntry}. * * @param entry the entry that was created for this pool */// ww w .j a v a 2s. c om public void createdEntry(final BasicPoolEntry entry) { Args.check(route.equals(entry.getPlannedRoute()), "Entry not planned for this pool"); numEntries++; }