/** * Creates a new route-specific pool. * Called by {@link #getRoutePool} when necessary. * * @param route the route * * @return the new pool */ protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) { return new RouteSpecificPool(route, connPerRoute.getMaxForRoute(route)); }
while(!done) { entry = rospl.allocEntry(state); + " [" + rospl.getRoute() + "][" + state + "]"); + " [" + rospl.getRoute() + "][" + state + "]"); closeConnection(entry.getConnection()); rospl.dropEntry(); numConnections--; } else { if (log.isDebugEnabled()) { log.debug("No free connections" + " [" + rospl.getRoute() + "][" + state + "]");
/** * Creates a new pool entry. * This method assumes that the new connection will be handed * out immediately. * * @param rospl the route-specific pool for which to create the entry * @param op the operator for creating a connection * * @return the new pool entry for a new connection */ protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { if (log.isDebugEnabled()) { log.debug("Creating new connection [" + rospl.getRoute() + "]"); } // the entry will create the connection when needed BasicPoolEntry entry = new BasicPoolEntry(op, rospl.getRoute(), refQueue); poolLock.lock(); try { rospl.createdEntry(entry); numConnections++; issuedConnections.add(entry.getWeakRef()); } finally { poolLock.unlock(); } return entry; }
try { if ((rospl != null) && rospl.hasThread()) { if (log.isDebugEnabled()) { log.debug("Notifying thread waiting on pool" + " [" + rospl.getRoute() + "]"); waitingThread = rospl.nextThread(); } else if (!waitingThreads.isEmpty()) { if (log.isDebugEnabled()) {
boolean hasCapacity = rospl.getCapacity() > 0; log.debug("Available capacity: " + rospl.getCapacity() + " out of " + rospl.getMaxEntries() + " [" + route + "][" + state + "]"); rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline); rospl.removeThread(waitingThread); waitingThreads.remove(waitingThread);
rospl.deleteEntry(entry); numConnections--; if (rospl.isUnused()) { routeToPool.remove(route);
if (reusable && rospl.getCapacity() >= 0) { if (log.isDebugEnabled()) { final String s; " [" + route + "][" + entry.getState() + "]; keep alive " + s); rospl.freeEntry(entry); entry.updateExpiry(validDuration, timeUnit); freeConnections.add(entry); } else { closeConnection(entry); rospl.dropEntry(); numConnections--;
public int getConnectionsInPool(HttpRoute route) { poolLock.lock(); try { // don't allow a pool to be created here! RouteSpecificPool rospl = getRoutePool(route, false); return (rospl != null) ? rospl.getEntryCount() : 0; } finally { poolLock.unlock(); } }
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or {@code null} if there is none */ public BasicPoolEntry allocEntry(final Object state) { if (!freeEntries.isEmpty()) { final ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size()); while (it.hasPrevious()) { final BasicPoolEntry entry = it.previous(); if (entry.getState() == null || LangUtils.equals(state, entry.getState())) { it.remove(); return entry; } } } if (getCapacity() == 0 && !freeEntries.isEmpty()) { final BasicPoolEntry entry = freeEntries.remove(); entry.shutdownEntry(); final OperatedClientConnection conn = entry.getConnection(); try { conn.close(); } catch (final IOException ex) { log.debug("I/O error closing connection", ex); } return entry; } return null; }
boolean hasCapacity = rospl.getCapacity() > 0; log.debug("Available capacity: " + rospl.getCapacity() + " out of " + rospl.getMaxEntries() + " [" + route + "][" + state + "]"); rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline); rospl.removeThread(waitingThread); waitingThreads.remove(waitingThread);
try { if ((rospl != null) && rospl.hasThread()) { if (log.isDebugEnabled()) { log.debug("Notifying thread waiting on pool" + " [" + rospl.getRoute() + "]"); waitingThread = rospl.nextThread(); } else if (!waitingThreads.isEmpty()) { if (log.isDebugEnabled()) {
/** * Deletes a given pool entry. * 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(); } }
if (reusable && rospl.getCapacity() >= 0) { if (log.isDebugEnabled()) { final String s; " [" + route + "][" + entry.getState() + "]; keep alive " + s); rospl.freeEntry(entry); entry.updateExpiry(validDuration, timeUnit); freeConnections.add(entry); } else { closeConnection(entry); rospl.dropEntry(); numConnections--;
public int getConnectionsInPool(HttpRoute route) { poolLock.lock(); try { // don't allow a pool to be created here! RouteSpecificPool rospl = getRoutePool(route, false); return (rospl != null) ? rospl.getEntryCount() : 0; } finally { poolLock.unlock(); } }
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or {@code null} if there is none */ public BasicPoolEntry allocEntry(final Object state) { if (!freeEntries.isEmpty()) { final ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size()); while (it.hasPrevious()) { final BasicPoolEntry entry = it.previous(); if (entry.getState() == null || LangUtils.equals(state, entry.getState())) { it.remove(); return entry; } } } if (getCapacity() == 0 && !freeEntries.isEmpty()) { final BasicPoolEntry entry = freeEntries.remove(); entry.shutdownEntry(); final OperatedClientConnection conn = entry.getConnection(); try { conn.close(); } catch (final IOException ex) { log.debug("I/O error closing connection", ex); } return entry; } return null; }
boolean hasCapacity = rospl.getCapacity() > 0; log.debug("Available capacity: " + rospl.getCapacity() + " out of " + rospl.getMaxEntries() + " [" + route + "][" + state + "]"); rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline); rospl.removeThread(waitingThread); waitingThreads.remove(waitingThread);