/** * 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; }
@Override public void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit) { HttpRoute route = entry.getPlannedRoute(); if (log.isDebugEnabled()) { log.debug("Freeing connection" + " [" + route + "][" + entry.getState() + "]"); closeConnection(entry.getConnection()); return; issuedConnections.remove(entry.getWeakRef()); rospl.freeEntry(entry); freeConnections.add(entry); idleConnHandler.add(entry.getConnection(), validDuration, timeUnit); } else { rospl.dropEntry();
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or <code>null</code> if there is none */ public BasicPoolEntry allocEntry(final Object state) { if (!freeEntries.isEmpty()) { ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size()); while (it.hasPrevious()) { BasicPoolEntry entry = it.previous(); if (LangUtils.equals(state, entry.getState())) { it.remove(); return entry; } } } if (!freeEntries.isEmpty()) { BasicPoolEntry entry = freeEntries.remove(); entry.setState(null); OperatedClientConnection conn = entry.getConnection(); try { conn.close(); } catch (IOException ex) { log.debug("I/O error closing connection", ex); } return entry; } return null; }
HttpRoute route = entry.getPlannedRoute(); + " [" + route + "][" + entry.getState() + "]"); try { closeConnection(entry.getConnection()); idleConnHandler.remove(entry.getConnection());// not idle, but dead
+ " [" + entry.getPlannedRoute() + "][" + entry.getState() + "]");
@Override public void deleteClosedConnections() { poolLock.lock(); try { Iterator<BasicPoolEntry> iter = freeConnections.iterator(); while (iter.hasNext()) { BasicPoolEntry entry = iter.next(); if (!entry.getConnection().isOpen()) { iter.remove(); deleteEntry(entry); } } } finally { poolLock.unlock(); } }
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or <code>null</code> 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; }
@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() + "]"); " [" + route + "][" + entry.getState() + "]; keep alive " + s); entry.updateExpiry(validDuration, timeUnit); freeConnections.add(entry); } else {
/** * Creates a new reference to a pool entry. * * @param entry the pool entry, must not be <code>null</code> * @param queue the reference queue, or <code>null</code> */ public BasicPoolEntryRef(BasicPoolEntry entry, ReferenceQueue<Object> queue) { super(entry, queue); if (entry == null) { throw new IllegalArgumentException ("Pool entry must not be null."); } route = entry.getPlannedRoute(); }
boolean valid = idleConnHandler.remove(entry.getConnection()); if(!valid) { log.debug("Closing expired free connection" + " [" + rospl.getRoute() + "][" + state + "]"); closeConnection(entry.getConnection()); numConnections--; } else { issuedConnections.add(entry.getWeakRef()); done = true;
@Override public void closeExpiredConnections() { log.debug("Closing expired connections"); final long now = System.currentTimeMillis(); poolLock.lock(); try { final Iterator<BasicPoolEntry> iter = freeConnections.iterator(); while (iter.hasNext()) { final BasicPoolEntry entry = iter.next(); if (entry.isExpired(now)) { if (log.isDebugEnabled()) { log.debug("Closing connection expired @ " + new Date(entry.getExpiry())); } iter.remove(); deleteEntry(entry); } } } finally { poolLock.unlock(); } }
/** * 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(final RouteSpecificPool rospl, final ClientConnectionOperator op) { if (log.isDebugEnabled()) { log.debug("Creating new connection [" + rospl.getRoute() + "]"); } // the entry will create the connection when needed final BasicPoolEntry entry = new BasicPoolEntry(op, rospl.getRoute(), connTTL, connTTLTimeUnit); poolLock.lock(); try { rospl.createdEntry(entry); numConnections++; leasedConnections.add(entry); } finally { poolLock.unlock(); } return entry; }
while (iter.hasNext()) { final BasicPoolEntry entry = iter.next(); if (entry.getUpdated() <= deadline) { if (log.isDebugEnabled()) { log.debug("Closing connection last used @ " + new Date(entry.getUpdated()));
if (entry.isExpired(System.currentTimeMillis())) {
HttpRoute route = entry.getPlannedRoute(); + " [" + route + "][" + entry.getState() + "]"); try { closeConnection(entry.getConnection()); idleConnHandler.remove(entry.getConnection());// not idle, but dead
+ " [" + entry.getPlannedRoute() + "][" + entry.getState() + "]");
@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(); } }
/** * 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; }
@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() + "]"); " [" + route + "][" + entry.getState() + "]; keep alive " + s); entry.updateExpiry(validDuration, timeUnit); freeConnections.add(entry); } else {
/** * 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 */ public void createdEntry(BasicPoolEntry entry) { if (!route.equals(entry.getPlannedRoute())) { throw new IllegalArgumentException ("Entry not planned for this pool." + "\npool: " + route + "\nplan: " + entry.getPlannedRoute()); } numEntries++; }