当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientConnection.shutdown方法代码示例

本文整理汇总了Java中org.apache.http.HttpClientConnection.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientConnection.shutdown方法的具体用法?Java HttpClientConnection.shutdown怎么用?Java HttpClientConnection.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpClientConnection的用法示例。


在下文中一共展示了HttpClientConnection.shutdown方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shutdownConnection

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
private void shutdownConnection(final HttpClientConnection conn) {
    try {
        conn.shutdown();
    } catch (final IOException iox) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("I/O exception shutting down connection", iox);
        }
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:10,代码来源:BasicClientConnectionManager.java

示例2: shutdownConnection

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
public void shutdownConnection() throws IOException {
    final HttpClientConnection conn = getConnection();
    conn.shutdown();
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:5,代码来源:CPoolEntry.java

示例3: testReleaseConnectionOnAbort

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
/**
 * Tests releasing connection from #abort method called from the
 * main execution thread while there is no blocking I/O operation.
 */
@Test
public void testReleaseConnectionOnAbort() throws Exception {

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final int      rsplen = 8;
    final String      uri = "/random/" + rsplen;
    final HttpContext context = new BasicHttpContext();

    final HttpRequest request =
        new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);

    HttpClientConnection conn = getConnection(this.connManager, route);
    this.connManager.connect(conn, route, 0, context);
    this.connManager.routeComplete(conn, route, context);

    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);

    final HttpProcessor httpProcessor = new ImmutableHttpProcessor(
            new HttpRequestInterceptor[] { new RequestContent(), new RequestConnControl() });

    final HttpRequestExecutor exec = new HttpRequestExecutor();
    exec.preProcess(request, httpProcessor, context);
    final HttpResponse response = exec.execute(request, conn, context);

    Assert.assertEquals("wrong status in first response",
                 HttpStatus.SC_OK,
                 response.getStatusLine().getStatusCode());

    // check that there are no connections available
    try {
        // this should fail quickly, connection has not been released
        getConnection(this.connManager, route, 100L, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException e) {
        // expected
    }

    // abort the connection
    Assert.assertTrue(conn instanceof HttpClientConnection);
    conn.shutdown();
    this.connManager.releaseConnection(conn, null, -1, null);

    // the connection is expected to be released back to the manager
    conn = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn.isOpen());

    this.connManager.releaseConnection(conn, null, -1, null);
    this.connManager.shutdown();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:58,代码来源:TestConnectionManagement.java

示例4: testAbortDuringConnecting

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
@Test
public void testAbortDuringConnecting() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.BEFORE_CONNECT, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("expected SocketException");
    } catch(final SocketException expected) {}

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:57,代码来源:TestConnectionManagement.java

示例5: testAbortBeforeSocketCreate

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
@Test
public void testAbortBeforeSocketCreate() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.BEFORE_CREATE, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("IOException expected");
    } catch(final IOException expected) {
    }

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:58,代码来源:TestConnectionManagement.java

示例6: testAbortAfterSocketConnect

import org.apache.http.HttpClientConnection; //导入方法依赖的package包/类
@Test
public void testAbortAfterSocketConnect() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.AFTER_CONNECT, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("IOException expected");
    } catch(final IOException expected) {
    }

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:58,代码来源:TestConnectionManagement.java


注:本文中的org.apache.http.HttpClientConnection.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。