/** * Returns a wrapped instance of {@link HttpClientConnectionManager} * to capture the necessary performance metrics. * * @param orig the target instance to be wrapped */ public static HttpClientConnectionManager wrap(HttpClientConnectionManager orig) { if (orig instanceof Wrapped) { throw new IllegalArgumentException(); } final Class<?>[] interfaces; if (orig instanceof ConnPoolControl) { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, ConnPoolControl.class, Wrapped.class}; } else { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, Wrapped.class }; } return (HttpClientConnectionManager) Proxy.newProxyInstance( // https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423 ClientConnectionManagerFactory.class.getClassLoader(), interfaces, new Handler(orig)); }
/** * Returns a wrapped instance of {@link HttpClientConnectionManager} * to capture the necessary performance metrics. * * @param orig the target instance to be wrapped */ public static HttpClientConnectionManager wrap (HttpClientConnectionManager orig) { if (orig instanceof Wrapped) throw new IllegalArgumentException(); final Class<?>[] interfaces; if (orig instanceof ConnPoolControl) { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, ConnPoolControl.class, Wrapped.class }; } else { interfaces = new Class<?>[]{ HttpClientConnectionManager.class, Wrapped.class }; } return (HttpClientConnectionManager) Proxy.newProxyInstance( // https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423 ClientConnectionManagerFactory.class.getClassLoader(), interfaces, new Handler(orig)); }
/** * Tests that a streaming operation has it's request properly cleaned up if the client is interrupted after the * response is received. * * @see TT0070103230 */ @Test public void clientInterruptedDuringResponseHandlers_DoesNotLeakConnection() throws IOException { ClientConfiguration config = new ClientConfiguration(); ConnectionManagerAwareHttpClient rawHttpClient = new ApacheHttpClientFactory().create(HttpClientSettings.adapt(config)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); interruptCurrentThreadAfterDelay(1000); List<RequestHandler2> requestHandlers = RequestHandlerTestUtils .buildRequestHandlerList(new SlowRequestHandler().withAfterResponseWaitInSeconds(10)); try { requestBuilder().executionContext(withHandlers(requestHandlers)).execute(new DummyResponseHandler().leaveConnectionOpen()); fail("Expected exception"); } catch (AmazonClientException e) { assertThat(e.getCause(), instanceOf(InterruptedException.class)); } @SuppressWarnings("deprecation") int leasedConnections = ((ConnPoolControl<?>) ((SdkHttpClient)rawHttpClient).getHttpClientConnectionManager()).getTotalStats().getLeased(); assertEquals(0, leasedConnections); }
public static AbstractHttpClient createHttpClient() { try { if (IS_HTTP_CLIENT_GE_4_2) { ClientConnectionManager poolingManager = (ClientConnectionManager) Class.forName( "org.apache.http.impl.conn.PoolingClientConnectionManager").newInstance(); ((ConnPoolControl<?>) poolingManager).setMaxTotal(DEFAULT_MAX_TOTAL); ((ConnPoolControl<?>) poolingManager).setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); return new DefaultHttpClient(poolingManager, (HttpParams) null); } else { return new ThreadSafeHttpClient(); } } catch (Exception e) { throw new IllegalStateException("Can not create http client.", e); } }
public ApacheHttpClient441BackedHttpClient(String scheme, String host, int port, OAuthSigner signer, CloseableHttpClient client, Closeable onClose, ConnPoolControl<HttpRoute> connPoolControl, Map<String, String> headersForEveryRequest) { this.scheme = scheme; this.host = host; this.port = port; this.oauthSigner = signer; this.client = client; this.onClose = onClose; this.connPoolControl = connPoolControl; this.headersForEveryRequest = headersForEveryRequest; }
/** * Captures the connection pool metrics. */ private void captureConnectionPoolMetrics() { if (awsRequestMetrics.isEnabled() && httpClient.getHttpClientConnectionManager() instanceof ConnPoolControl<?>) { final PoolStats stats = ((ConnPoolControl<?>) httpClient .getHttpClientConnectionManager()).getTotalStats(); awsRequestMetrics .withCounter(HttpClientPoolAvailableCount, stats.getAvailable()) .withCounter(HttpClientPoolLeasedCount, stats.getLeased()) .withCounter(HttpClientPoolPendingCount, stats.getPending()); } }
AIMDBackoffManager(ConnPoolControl<HttpRoute> connPerRoute, Clock clock) { this.clock = clock; this.connPerRoute = connPerRoute; this.lastRouteProbes = new HashMap<HttpRoute,Long>(); this.lastRouteBackoffs = new HashMap<HttpRoute,Long>(); }
public HTTPCAsyncClientMonitor(String poolName, ConnPoolControl<HttpRoute> pool) { super(poolName, pool); }
public HTTPCClientMonitor(String poolName, ConnPoolControl<HttpRoute> pool) { this.poolName = poolName; this.pool = pool; this.future = HTTPCClientMonitorExecutor.pool.scheduleAtFixedRate(this, 5, 30, TimeUnit.SECONDS); }
public HTTPCSyncClientMonitor(String poolName, ConnPoolControl<HttpRoute> pool) { super(poolName, pool); }
AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute, final Clock clock) { this.clock = clock; this.connPerRoute = connPerRoute; this.lastRouteProbes = new HashMap<HttpRoute,Long>(); this.lastRouteBackoffs = new HashMap<HttpRoute,Long>(); }
/** * Creates an <code>AIMDBackoffManager</code> to manage * per-host connection pool sizes represented by the * given {@link ConnPoolControl}. * @param connPerRoute per-host routing maximums to * be managed */ public AIMDBackoffManager(ConnPoolControl<HttpRoute> connPerRoute) { this(connPerRoute, new SystemClock()); }
/** * Creates an <code>AIMDBackoffManager</code> to manage * per-host connection pool sizes represented by the * given {@link ConnPoolControl}. * @param connPerRoute per-host routing maximums to * be managed */ public AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute) { this(connPerRoute, new SystemClock()); }
/** * Creates an {@code AIMDBackoffManager} to manage * per-host connection pool sizes represented by the * given {@link ConnPoolControl}. * @param connPerRoute per-host routing maximums to * be managed */ public AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute) { this(connPerRoute, new SystemClock()); }
/** * Gets the {@link ConnPoolControl}. * * @return the {@link ConnPoolControl} */ public ConnPoolControl getConnPoolControl() { return connPoolControl; }