Java 类org.apache.http.pool.PoolStats 实例源码

项目:cloud-meter    文件:JMeterPoolingClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:marmotta    文件:HttpClientServiceImpl.java   
@Override
public Map<String, String> getStatistics() {
    int i = 0;
    final Map<String, String> data = new LinkedHashMap<String, String>();
    data.put(KEYS[i++], String.valueOf(requestsExecuted.get()));
    data.put(KEYS[i++], humanReadableBytes(bytesSent.get(), false));
    data.put(KEYS[i++], humanReadableBytes(bytesReceived.get(), false));
    data.put(KEYS[i++], humanReadableBytes(bytesFromCache.get(), false));

    final PoolStats cmStats = connectionManager.getTotalStats();
    data.put(KEYS[i++], connectionManager.getClass().getSimpleName());
    data.put(KEYS[i++], String.valueOf(cmStats.getMax()));
    data.put(KEYS[i++], String.valueOf(cmStats.getAvailable()));
    data.put(KEYS[i++], String.valueOf(cmStats.getLeased()));
    data.put(KEYS[i++], String.valueOf(cmStats.getPending()));
    return data;
}
项目:lams    文件:PoolingClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    StringBuilder buf = new StringBuilder();
    PoolStats totals = this.pool.getTotalStats();
    PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:java-restclient    文件:HTTPCClientMonitor.java   
public void run() {
    PoolStats stats = pool.getTotalStats();

    Metrics.INSTANCE.count("restclient.httpc.pool.available", stats.getAvailable(), "rest_pool:" + poolName, "type:" + getType());
    Metrics.INSTANCE.count("restclient.httpc.pool.leased", stats.getLeased(), "rest_pool:" + poolName, "type:" + getType());
    Metrics.INSTANCE.count("restclient.httpc.pool.pending", stats.getPending(), "rest_pool:" + poolName, "type:" + getType());
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClient.java   
/**
 * 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());
    }

}
项目:remote-files-sync    文件:PoolingHttpClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:purecloud-iot    文件:PoolingClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:purecloud-iot    文件:PoolingHttpClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:purecloud-iot    文件:TestConnectionAutoRelease.java   
@Test
public void testReleaseOnEntityConsumeContent() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();
    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    EntityUtils.consume(e);

    // Expect one connection in the pool
    stats = this.connManager.getTotalStats();
    Assert.assertEquals(1, stats.getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
项目:purecloud-iot    文件:TestConnectionAutoRelease.java   
@Test
public void testReleaseOnEntityWriteTo() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();
    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
    e.writeTo(outsteam);

    // Expect one connection in the pool
    stats = this.connManager.getTotalStats();
    Assert.assertEquals(1, stats.getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
项目:purecloud-iot    文件:TestConnectionAutoRelease.java   
@Test
public void testReleaseOnAbort() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    final PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();

    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    httpget.abort();

    // Expect zero connections in the pool
    Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
项目:Visit    文件:PoolingHttpClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:routing-bird    文件:ApacheHttpClient441BackedHttpClient.java   
@Override
public HttpClientPoolStats getPoolStats() {
    PoolStats totalStats = connPoolControl.getTotalStats();
    return new HttpClientPoolStats(totalStats.getLeased(),
        totalStats.getPending(),
        totalStats.getAvailable(),
        totalStats.getMax());
}
项目:OpsDev    文件:NHttpReverseProxy.java   
public void release(final BasicNIOPoolEntry entry, boolean reusable) {
    System.out.println("[proxy->origin] connection released " + entry.getConnection());
    ConsoleFactory.printToConsole("[proxy->origin] connection released " + entry.getConnection(),true);
    super.release(entry, reusable);
    StringBuilder buf = new StringBuilder();
    PoolStats totals = getTotalStats();
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    System.out.println("[proxy->origin] " + buf.toString());
    ConsoleFactory.printToConsole("[proxy->origin] " + buf.toString(),true);
}
项目:Sql4D    文件:DruidNodeAccessor.java   
public static Map<String, Integer> getConnectionPoolStats() {
    Map<String, Integer> stats = new HashMap<>();
    PoolStats poolStats = pool.getTotalStats();
    stats.put("availableConnections", poolStats.getAvailable());
    stats.put("maxConnections", poolStats.getMax());
    stats.put("leasedConnections", poolStats.getLeased());
    stats.put("pendingConnections", poolStats.getPending());
    stats.put("defaultMaxPerRoute", pool.getDefaultMaxPerRoute());
    return stats;
}
项目:ZTLib    文件:PoolingHttpClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    final StringBuilder buf = new StringBuilder();
    final PoolStats totals = this.pool.getTotalStats();
    final PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:datarouter    文件:DatarouterHttpClient.java   
public PoolStats getPoolStats(){
    return connectionManager.getTotalStats();
}
项目:lams    文件:PoolingClientConnectionManager.java   
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:lams    文件:PoolingClientConnectionManager.java   
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:remote-files-sync    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:remote-files-sync    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:cloud-meter    文件:JMeterPoolingClientConnectionManager.java   
@Override
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:cloud-meter    文件:JMeterPoolingClientConnectionManager.java   
@Override
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:purecloud-iot    文件:PoolingClientConnectionManager.java   
@Override
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:purecloud-iot    文件:PoolingClientConnectionManager.java   
@Override
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:purecloud-iot    文件:PoolingHttpClientConnectionManager.java   
@Override
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:purecloud-iot    文件:PoolingHttpClientConnectionManager.java   
@Override
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:purecloud-iot    文件:MockConnPoolControl.java   
@Override
public PoolStats getTotalStats() {
    return new PoolStats(-1, -1, -1, this.totalMax);
}
项目:purecloud-iot    文件:MockConnPoolControl.java   
@Override
public PoolStats getStats(final HttpRoute route) {
    return new PoolStats(-1, -1, -1, getMaxPerRoute(route));
}
项目:Visit    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:Visit    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:Poseidon    文件:HttpConnectionPool.java   
/**
 * Get the statistics
 */
public String getStats() {
    PoolingClientConnectionManager cm = (PoolingClientConnectionManager) this.client.getConnectionManager();
    PoolStats stats = cm.getTotalStats();
    return "Connections: " + stats.toString() + " AvailableRequests: " + processQueue.availablePermits();
}
项目:stability-utils    文件:PooledHttpClientStrategy.java   
public PoolStats getPoolStats()
{
    return getConnectionManager().getTotalStats();
}
项目:data-prep    文件:APIService.java   
/**
 * @return the connection pool stats.
 */
protected PoolStats getConnectionStats() {
    return connectionManager.getTotalStats();
}
项目:uw-android    文件:ClientEvictExpiredConnections.java   
public static void main(String[] args) throws Exception {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(100);
    CloseableHttpClient httpclient = HttpClients.custom()
            .setConnectionManager(cm)
            .evictExpiredConnections()
            .evictIdleConnections(5L, TimeUnit.SECONDS)
            .build();
    try {
        // create an array of URIs to perform GETs on
        String[] urisToGet = {
            "http://hc.apache.org/",
            "http://hc.apache.org/httpcomponents-core-ga/",
            "http://hc.apache.org/httpcomponents-client-ga/",
        };

        for (int i = 0; i < urisToGet.length; i++) {
            String requestURI = urisToGet[i];
            HttpGet request = new HttpGet(requestURI);

            System.out.println("Executing request " + requestURI);

            CloseableHttpResponse response = httpclient.execute(request);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(response.getEntity());
            } finally {
                response.close();
            }
        }

        PoolStats stats1 = cm.getTotalStats();
        System.out.println("Connections kept alive: " + stats1.getAvailable());

        // Sleep 10 sec and let the connection evictor do its job
        Thread.sleep(10000);

        PoolStats stats2 = cm.getTotalStats();
        System.out.println("Connections kept alive: " + stats2.getAvailable());

    } finally {
        httpclient.close();
    }
}
项目:ZTLib    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getTotalStats() {
    return this.pool.getTotalStats();
}
项目:ZTLib    文件:PoolingHttpClientConnectionManager.java   
public PoolStats getStats(final HttpRoute route) {
    return this.pool.getStats(route);
}
项目:purecloud-iot    文件:ClientEvictExpiredConnections.java   
public static void main(String[] args) throws Exception {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(100);
    CloseableHttpClient httpclient = HttpClients.custom()
            .setConnectionManager(cm)
            .evictExpiredConnections()
            .evictIdleConnections(5L, TimeUnit.SECONDS)
            .build();
    try {
        // create an array of URIs to perform GETs on
        String[] urisToGet = {
            "http://hc.apache.org/",
            "http://hc.apache.org/httpcomponents-core-ga/",
            "http://hc.apache.org/httpcomponents-client-ga/",
        };

        for (int i = 0; i < urisToGet.length; i++) {
            String requestURI = urisToGet[i];
            HttpGet request = new HttpGet(requestURI);

            System.out.println("Executing request " + requestURI);

            CloseableHttpResponse response = httpclient.execute(request);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            } finally {
                response.close();
            }
        }

        PoolStats stats1 = cm.getTotalStats();
        System.out.println("Connections kept alive: " + stats1.getAvailable());

        // Sleep 10 sec and let the connection evictor do its job
        Thread.sleep(10000);

        PoolStats stats2 = cm.getTotalStats();
        System.out.println("Connections kept alive: " + stats2.getAvailable());

    } finally {
        httpclient.close();
    }
}