org.apache.http.pool.ConnPoolControl Java Examples
The following examples show how to use
org.apache.http.pool.ConnPoolControl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientConnectionManagerFactory.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * 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(); } 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)); }
Example #2
Source File: ClientConnectionManagerFactory.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * 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)); }
Example #3
Source File: DummySuccessfulResponseServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * 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); }
Example #4
Source File: PoolingHttpClientConnectionManagerMetricsBinder.java From micrometer with Apache License 2.0 | 5 votes |
private void registerTotalMetrics(MeterRegistry registry) { Gauge.builder("httpcomponents.httpclient.pool.total.max", connPoolControl, (connPoolControl) -> connPoolControl.getTotalStats().getMax()) .description("The configured maximum number of allowed persistent connections for all routes.") .tags(tags) .register(registry); Gauge.builder("httpcomponents.httpclient.pool.total.connections", connPoolControl, (connPoolControl) -> connPoolControl.getTotalStats().getAvailable()) .description("The number of persistent and available connections for all routes.") .tags(tags).tag("state", "available") .register(registry); Gauge.builder("httpcomponents.httpclient.pool.total.connections", connPoolControl, (connPoolControl) -> connPoolControl.getTotalStats().getLeased()) .description("The number of persistent and leased connections for all routes.") .tags(tags).tag("state", "leased") .register(registry); Gauge.builder("httpcomponents.httpclient.pool.total.pending", connPoolControl, (connPoolControl) -> connPoolControl.getTotalStats().getPending()) .description("The number of connection requests being blocked awaiting a free connection for all routes.") .tags(tags) .register(registry); Gauge.builder("httpcomponents.httpclient.pool.route.max.default", connPoolControl, ConnPoolControl::getDefaultMaxPerRoute) .description("The configured default maximum number of allowed persistent connections per route.") .tags(tags) .register(registry); }
Example #5
Source File: PoolingHttpClientConnectionManagerMetricsBinderTest.java From micrometer with Apache License 2.0 | 5 votes |
@BeforeEach @SuppressWarnings("unchecked") void setup() { connPoolControl = (ConnPoolControl<HttpRoute>) mock(ConnPoolControl.class); binder = new PoolingHttpClientConnectionManagerMetricsBinder(connPoolControl, "test"); binder.bindTo(registry); }
Example #6
Source File: AmazonHttpClient.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
/** * 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()); } }
Example #7
Source File: PoolingHttpClientConnectionManagerMetricsBinder.java From micrometer with Apache License 2.0 | 2 votes |
/** * Creates a metrics binder for the given pooling connection pool control. * * @param connPoolControl The connection pool control to monitor. * @param name Name of the connection pool control. Will be added as tag with the * key "httpclient". * @param tags Tags to apply to all recorded metrics. Must be an even number * of arguments representing key/value pairs of tags. */ @SuppressWarnings("WeakerAccess") public PoolingHttpClientConnectionManagerMetricsBinder(ConnPoolControl<HttpRoute> connPoolControl, String name, String... tags) { this(connPoolControl, name, Tags.of(tags)); }
Example #8
Source File: PoolingHttpClientConnectionManagerMetricsBinder.java From micrometer with Apache License 2.0 | 2 votes |
/** * Creates a metrics binder for the given connection pool control. * * @param connPoolControl The connection pool control to monitor. * @param name Name of the connection pool control. Will be added as tag with the key "httpclient". * @param tags Tags to apply to all recorded metrics. */ @SuppressWarnings("WeakerAccess") public PoolingHttpClientConnectionManagerMetricsBinder(ConnPoolControl<HttpRoute> connPoolControl, String name, Iterable<Tag> tags) { this.connPoolControl = connPoolControl; this.tags = Tags.concat(tags, "httpclient", name); }