Search in sources :

Example 1 with NoOpMetricCollector

use of software.amazon.awssdk.metrics.NoOpMetricCollector in project aws-sdk-java-v2 by aws.

the class ApacheHttpClient method prepareRequest.

@Override
public ExecutableHttpRequest prepareRequest(HttpExecuteRequest request) {
    MetricCollector metricCollector = request.metricCollector().orElseGet(NoOpMetricCollector::create);
    metricCollector.reportMetric(HTTP_CLIENT_NAME, clientName());
    HttpRequestBase apacheRequest = toApacheRequest(request);
    return new ExecutableHttpRequest() {

        @Override
        public HttpExecuteResponse call() throws IOException {
            HttpExecuteResponse executeResponse = execute(apacheRequest, metricCollector);
            collectPoolMetric(metricCollector);
            return executeResponse;
        }

        @Override
        public void abort() {
            apacheRequest.abort();
        }
    };
}
Also used : NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest)

Example 2 with NoOpMetricCollector

use of software.amazon.awssdk.metrics.NoOpMetricCollector in project aws-sdk-java-v2 by aws.

the class ApacheHttpClient method collectPoolMetric.

private void collectPoolMetric(MetricCollector metricCollector) {
    HttpClientConnectionManager cm = httpClient.getHttpClientConnectionManager();
    if (cm instanceof PoolingHttpClientConnectionManager && !(metricCollector instanceof NoOpMetricCollector)) {
        PoolingHttpClientConnectionManager poolingCm = (PoolingHttpClientConnectionManager) cm;
        PoolStats totalStats = poolingCm.getTotalStats();
        metricCollector.reportMetric(MAX_CONCURRENCY, totalStats.getMax());
        metricCollector.reportMetric(AVAILABLE_CONCURRENCY, totalStats.getAvailable());
        metricCollector.reportMetric(LEASED_CONCURRENCY, totalStats.getLeased());
        metricCollector.reportMetric(PENDING_CONCURRENCY_ACQUIRES, totalStats.getPending());
    }
}
Also used : NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) PoolStats(org.apache.http.pool.PoolStats)

Aggregations

NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 HttpClientConnectionManager (org.apache.http.conn.HttpClientConnectionManager)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 PoolStats (org.apache.http.pool.PoolStats)1 ExecutableHttpRequest (software.amazon.awssdk.http.ExecutableHttpRequest)1 HttpExecuteResponse (software.amazon.awssdk.http.HttpExecuteResponse)1 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)1