@Override public void release(final PoolEntry<T, C> entry, final boolean reusable) { if (entry == null) { return; } if (isShutDown.get()) { return; } final PerRoutePool<T, C> routePool = getPool(entry.getRoute()); if (connPoolListener != null) { connPoolListener.onLease(entry.getRoute(), this); } routePool.release(entry, reusable); }
@Override public void release(final PoolEntry<T, C> entry, final boolean reusable) { if (entry == null) { return; } if (isShutDown.get()) { return; } final PerRoutePool<T, C> routePool = getPool(entry.getRoute()); if (connPoolListener != null) { connPoolListener.onLease(entry.getRoute(), this); } routePool.release(entry, reusable); }
/** * Enumerates all available connections. * * @since 4.3 */ public void enumAvailable(final Callback<PoolEntry<T, C>> callback) { this.lock.lock(); try { final Iterator<PoolEntry<T, C>> it = this.available.iterator(); while (it.hasNext()) { final PoolEntry<T, C> entry = it.next(); callback.execute(entry); if (!entry.hasConnection()) { final PerRoutePool<T, C> pool = getPool(entry.getRoute()); pool.remove(entry); it.remove(); } } processPendingRequests(); purgePoolMap(); } finally { this.lock.unlock(); } }
/** * Enumerates all available connections. * * @since 4.3 */ public void enumAvailable(final Callback<PoolEntry<T, C>> callback) { this.lock.lock(); try { final Iterator<PoolEntry<T, C>> it = this.available.iterator(); while (it.hasNext()) { final PoolEntry<T, C> entry = it.next(); callback.execute(entry); if (!entry.hasConnection()) { final PerRoutePool<T, C> pool = getPool(entry.getRoute()); pool.remove(entry); it.remove(); } } processPendingRequests(); purgePoolMap(); } finally { this.lock.unlock(); } }
@Override public void upgrade( final AsyncConnectionEndpoint endpoint, final Object attachment, final HttpContext context) { Args.notNull(endpoint, "Managed endpoint"); final InternalConnectionEndpoint internalEndpoint = cast(endpoint); final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = internalEndpoint.getValidatedPoolEntry(); final HttpRoute route = poolEntry.getRoute(); final ManagedAsyncClientConnection connection = poolEntry.getConnection(); connectionOperator.upgrade(poolEntry.getConnection(), route.getTargetHost(), attachment); if (log.isDebugEnabled()) { log.debug(ConnPoolSupport.getId(internalEndpoint) + ": upgraded " + ConnPoolSupport.getId(connection)); } }
@Override public void upgrade(final ConnectionEndpoint endpoint, final HttpContext context) throws IOException { Args.notNull(endpoint, "Managed endpoint"); final InternalConnectionEndpoint internalEndpoint = cast(endpoint); final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry = internalEndpoint.getValidatedPoolEntry(); final HttpRoute route = poolEntry.getRoute(); this.connectionOperator.upgrade(poolEntry.getConnection(), route.getTargetHost(), context); }
if (log.isDebugEnabled()) { log.debug("Connection released: " + ConnPoolSupport.formatStats( connection, entry.getRoute(), entry.getState(), pool));
request.completed(entry); if (this.connPoolListener != null) { this.connPoolListener.onLease(entry.getRoute(), this); final PoolEntry<T, C> lastUsed = this.available.removeLast(); lastUsed.discardConnection(CloseMode.GRACEFUL); final PerRoutePool<T, C> otherpool = getPool(lastUsed.getRoute()); otherpool.remove(lastUsed); request.completed(entry); if (this.connPoolListener != null) { this.connPoolListener.onLease(entry.getRoute(), this);
request.completed(entry); if (this.connPoolListener != null) { this.connPoolListener.onLease(entry.getRoute(), this); final PoolEntry<T, C> lastUsed = this.available.removeLast(); lastUsed.discardConnection(CloseMode.GRACEFUL); final PerRoutePool<T, C> otherpool = getPool(lastUsed.getRoute()); otherpool.remove(lastUsed); request.completed(entry); if (this.connPoolListener != null) { this.connPoolListener.onLease(entry.getRoute(), this);
if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + ConnPoolSupport.formatStats( conn, entry.getRoute(), entry.getState(), pool));
@Override public void connect(final ConnectionEndpoint endpoint, final TimeValue connectTimeout, final HttpContext context) throws IOException { Args.notNull(endpoint, "Managed endpoint"); final InternalConnectionEndpoint internalEndpoint = cast(endpoint); if (internalEndpoint.isConnected()) { return; } final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry = internalEndpoint.getPoolEntry(); if (!poolEntry.hasConnection()) { poolEntry.assignConnection(connFactory.createConnection(null)); } final HttpRoute route = poolEntry.getRoute(); final HttpHost host; if (route.getProxyHost() != null) { host = route.getProxyHost(); } else { host = route.getTargetHost(); } this.connectionOperator.connect( poolEntry.getConnection(), host, route.getLocalSocketAddress(), connectTimeout, defaultSocketConfig != null ? this.defaultSocketConfig : SocketConfig.DEFAULT, context); }
@Test public void testBasics() throws Exception { final PoolEntry<String, HttpConnection> entry1 = new PoolEntry<>( "route1", TimeValue.of(10L, TimeUnit.MILLISECONDS), currentTimeSupplier); Assert.assertEquals("route1", entry1.getRoute()); Assert.assertEquals(0, entry1.getUpdated()); Assert.assertEquals(Deadline.MIN_VALUE, entry1.getExpiryDeadline()); entry1.assignConnection(Mockito.mock(HttpConnection.class)); final long now = System.currentTimeMillis(); Assert.assertEquals("route1", entry1.getRoute()); Assert.assertTrue(now >= entry1.getUpdated()); Assert.assertEquals(entry1.getValidityDeadline(), entry1.getExpiryDeadline()); Assert.assertEquals(entry1.getUpdated() + 10L, entry1.getValidityDeadline().getValue()); entry1.discardConnection(CloseMode.IMMEDIATE); Assert.assertEquals(0, entry1.getUpdated()); Assert.assertEquals(Deadline.MIN_VALUE, entry1.getExpiryDeadline()); }
final HttpRoute route = poolEntry.getRoute(); final HttpHost host; if (route.getProxyHost() != null) {