try { RouteSpecificPool rospl = getRoutePool(route, true); WaitingThread waitingThread = null; entry = getFreeEntry(rospl, state); if (entry != null) { break; entry = createEntry(rospl, operator); deleteLeastUsedEntry(); entry = createEntry(rospl, operator); newWaitingThread(poolLock.newCondition(), rospl); aborter.setWaitingThread(waitingThread);
@Override protected void deleteEntry(BasicPoolEntry entry) { deleteCounter.increment(); super.deleteEntry(entry); }
public BasicPoolEntry getPoolEntry( long timeout, TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { return getEntryBlocking(route, state, timeout, tunit, aborter); }
/** * Creates a new connection pool, managed by route. */ public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) { super(); if (operator == null) { throw new IllegalArgumentException("Connection operator may not be null"); } this.operator = operator; freeConnections = createFreeConnQueue(); waitingThreads = createWaitingThreadQueue(); routeToPool = createRouteToPoolMap(); maxTotalConnections = ConnManagerParams .getMaxTotalConnections(params); connPerRoute = ConnManagerParams .getMaxConnectionsPerRoute(params); }
closeConnection(entry.getConnection()); return; RouteSpecificPool rospl = getRoutePool(route, true); notifyWaitingThread(rospl);
try { closeConnection(entry.getConnection()); RouteSpecificPool rospl = getRoutePool(route, true); rospl.deleteEntry(entry); numConnections--;
/** * Hook for creating the connection pool. * * @return the connection pool to use */ protected AbstractConnPool createConnectionPool(final HttpParams params) { AbstractConnPool acp = new ConnPoolByRoute(connOperator, params); boolean conngc = true; //@@@ check parameters to decide if (conngc) { acp.enableConnectionGC(); } return acp; }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
@Override protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { createEntryCounter.increment(); Stopwatch stopWatch = creationTimer.start(); try { return super.createEntry(rospl, op); } finally { stopWatch.stop(); } }
@Override protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, Object state) { BasicPoolEntry entry = super.getFreeEntry(rospl, state); if (entry != null) { freeEntryCounter.increment(); } return entry; }
/** * Creates a new connection pool, managed by route. */ public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) { super(); if (operator == null) { throw new IllegalArgumentException("Connection operator may not be null"); } this.operator = operator; freeConnections = createFreeConnQueue(); waitingThreads = createWaitingThreadQueue(); routeToPool = createRouteToPoolMap(); maxTotalConnections = ConnManagerParams .getMaxTotalConnections(params); connPerRoute = ConnManagerParams .getMaxConnectionsPerRoute(params); }
closeConnection(entry.getConnection()); return; RouteSpecificPool rospl = getRoutePool(route, true); notifyWaitingThread(rospl);
/** * 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(); } }
/** * Hook for creating the connection pool. * * @return the connection pool to use * * @since 4.1 */ protected ConnPoolByRoute createConnectionPool(final long connTTL, final TimeUnit connTTLTimeUnit) { return new ConnPoolByRoute(connOperator, connPerRoute, 20, connTTL, connTTLTimeUnit); }
log.debug("Closing expired free connection" + " [" + rospl.getRoute() + "][" + state + "]"); closeConnection(entry.getConnection());
@Override protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { createEntryCounter.increment(); Stopwatch stopWatch = creationTimer.start(); try { return super.createEntry(rospl, op); } finally { stopWatch.stop(); } }
@Override protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, Object state) { BasicPoolEntry entry = super.getFreeEntry(rospl, state); if (entry != null) { freeEntryCounter.increment(); } return entry; }
try { RouteSpecificPool rospl = getRoutePool(route, true); WaitingThread waitingThread = null; entry = getFreeEntry(rospl, state); if (entry != null) { break; entry = createEntry(rospl, operator); deleteLeastUsedEntry(); entry = createEntry(rospl, operator); newWaitingThread(poolLock.newCondition(), rospl); aborter.setWaitingThread(waitingThread);
/** * Creates a new connection pool, managed by route. */ public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) { super(); if (operator == null) { throw new IllegalArgumentException("Connection operator may not be null"); } this.operator = operator; freeConnections = createFreeConnQueue(); waitingThreads = createWaitingThreadQueue(); routeToPool = createRouteToPoolMap(); maxTotalConnections = ConnManagerParams .getMaxTotalConnections(params); connPerRoute = ConnManagerParams .getMaxConnectionsPerRoute(params); }
/** * Delete an old, free pool entry to make room for a new one. * Used to replace pool entries with ones for a different route. */ protected void deleteLeastUsedEntry() { try { poolLock.lock(); //@@@ with get() instead of remove, we could //@@@ leave the removing to deleteEntry() BasicPoolEntry entry = freeConnections.remove(); if (entry != null) { deleteEntry(entry); } else if (log.isDebugEnabled()) { log.debug("No free connection to delete."); } } finally { poolLock.unlock(); } }