/// <exception cref="System.Exception"></exception> /// <exception cref="Sharpen.ExecutionException"></exception> /// <exception cref="Apache.Http.Conn.ConnectionPoolTimeoutException"></exception> protected internal virtual HttpClientConnection LeaseConnection(Future <CPoolEntry > future, long timeout, TimeUnit tunit) { CPoolEntry entry; try { entry = future.Get(timeout, tunit); if (entry == null || future.IsCancelled()) { throw new Exception(); } Asserts.Check(entry.GetConnection() != null, "Pool entry with no connection"); if (this.log.IsDebugEnabled()) { this.log.Debug("Connection leased: " + Format(entry) + FormatStats(entry.GetRoute ())); } return(CPoolProxy.NewProxy(entry)); } catch (TimeoutException) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool" ); } }
/// <exception cref="System.IO.IOException"></exception> public virtual void RouteComplete(HttpClientConnection managedConn, HttpRoute route , HttpContext context) { Args.NotNull(managedConn, "Managed Connection"); Args.NotNull(route, "HTTP route"); lock (managedConn) { CPoolEntry entry = CPoolProxy.GetPoolEntry(managedConn); entry.MarkRouteComplete(); } }
/// <exception cref="System.IO.IOException"></exception> public virtual void Upgrade(HttpClientConnection managedConn, HttpRoute route, HttpContext context) { Args.NotNull(managedConn, "Managed Connection"); Args.NotNull(route, "HTTP route"); ManagedHttpClientConnection conn; lock (managedConn) { CPoolEntry entry = CPoolProxy.GetPoolEntry(managedConn); conn = entry.GetConnection(); } this.connectionOperator.Upgrade(conn, route.GetTargetHost(), context); }
public virtual void ReleaseConnection(HttpClientConnection managedConn, object state , long keepalive, TimeUnit tunit) { Args.NotNull(managedConn, "Managed connection"); lock (managedConn) { CPoolEntry entry = CPoolProxy.Detach(managedConn); if (entry == null) { return; } ManagedHttpClientConnection conn = entry.GetConnection(); try { if (conn.IsOpen()) { entry.SetState(state); entry.UpdateExpiry(keepalive, tunit != null ? tunit : TimeUnit.Milliseconds); if (this.log.IsDebugEnabled()) { string s; if (keepalive > 0) { s = "for " + (double)keepalive / 1000 + " seconds"; } else { s = "indefinitely"; } this.log.Debug("Connection " + Format(entry) + " can be kept alive " + s); } } } finally { this.pool.Release(entry, conn.IsOpen() && entry.IsRouteComplete()); if (this.log.IsDebugEnabled()) { this.log.Debug("Connection released: " + Format(entry) + FormatStats(entry.GetRoute ())); } } } }
/// <exception cref="System.IO.IOException"></exception> public virtual void Connect(HttpClientConnection managedConn, HttpRoute route, int connectTimeout, HttpContext context) { Args.NotNull(managedConn, "Managed Connection"); Args.NotNull(route, "HTTP route"); ManagedHttpClientConnection conn; lock (managedConn) { CPoolEntry entry = CPoolProxy.GetPoolEntry(managedConn); conn = entry.GetConnection(); } HttpHost host; if (route.GetProxyHost() != null) { host = route.GetProxyHost(); } else { host = route.GetTargetHost(); } IPEndPoint localAddress = route.GetLocalSocketAddress(); SocketConfig socketConfig = this.configData.GetSocketConfig(host); if (socketConfig == null) { socketConfig = this.configData.GetDefaultSocketConfig(); } if (socketConfig == null) { socketConfig = SocketConfig.Default; } this.connectionOperator.Connect(conn, host, localAddress, connectTimeout, socketConfig , context); }