本文整理汇总了Java中org.apache.http.conn.ConnectionRequest类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionRequest类的具体用法?Java ConnectionRequest怎么用?Java ConnectionRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionRequest类属于org.apache.http.conn包,在下文中一共展示了ConnectionRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
public final ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
Args.notNull(route, "Route");
return new ConnectionRequest() {
public boolean cancel() {
// Nothing to abort, since requests are immediate.
return false;
}
public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
return BasicHttpClientConnectionManager.this.getConnection(
route, state);
}
};
}
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:BasicHttpClientConnectionManager.java
示例2: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
public ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
Args.notNull(route, "HTTP route");
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Connection request: " + format(route, state) + formatStats(route));
}
final Future<CPoolEntry> future = this.pool.lease(route, state, null);
return new ConnectionRequest() {
public boolean cancel() {
return future.cancel(true);
}
public HttpClientConnection get(
final long timeout,
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
return leaseConnection(future, timeout, tunit);
}
};
}
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:24,代码来源:PoolingHttpClientConnectionManager.java
示例3: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Override
public final ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
Args.notNull(route, "Route");
return new ConnectionRequest() {
@Override
public boolean cancel() {
// Nothing to abort, since requests are immediate.
return false;
}
@Override
public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
return BasicHttpClientConnectionManager.this.getConnection(
route, state);
}
};
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:BasicHttpClientConnectionManager.java
示例4: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Override
public ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
Args.notNull(route, "HTTP route");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection request: " + format(route, state) + formatStats(route));
}
final Future<CPoolEntry> future = this.pool.lease(route, state, null);
return new ConnectionRequest() {
@Override
public boolean cancel() {
return future.cancel(true);
}
@Override
public HttpClientConnection get(
final long timeout,
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
return leaseConnection(future, timeout, tunit);
}
};
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:PoolingHttpClientConnectionManager.java
示例5: testLeaseReleaseNonReusable
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test
public void testLeaseReleaseNonReusable() throws Exception {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(connFactory.create(
Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
Assert.assertFalse(conn1.isOpen());
mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
Assert.assertNull(mgr.getRoute());
Assert.assertNull(mgr.getState());
final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn2);
Assert.assertFalse(conn2.isOpen());
Mockito.verify(connFactory, Mockito.times(2)).create(
Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestBasicHttpClientConnectionManager.java
示例6: testAlreadyLeased
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test(expected=IllegalStateException.class)
public void testAlreadyLeased() throws Exception {
final HttpHost target = new HttpHost("somehost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(connFactory.create(
Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
mgr.getConnection(route, null);
mgr.getConnection(route, null);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestBasicHttpClientConnectionManager.java
示例7: testLeaseFutureCancelled
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test(expected=InterruptedException.class)
public void testLeaseFutureCancelled() throws Exception {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
final CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
-1, TimeUnit.MILLISECONDS);
entry.markRouteComplete();
Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
connRequest1.get(1, TimeUnit.SECONDS);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestPoolingHttpClientConnectionManager.java
示例8: testReleaseReusable
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test
public void testReleaseReusable() throws Exception {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
final CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
-1, TimeUnit.MILLISECONDS));
entry.markRouteComplete();
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
Assert.assertNotNull(conn1);
Assert.assertTrue(conn1.isOpen());
mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);
Mockito.verify(pool).release(entry, true);
Mockito.verify(entry).setState("some state");
Mockito.verify(entry).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestPoolingHttpClientConnectionManager.java
示例9: testReleaseNonReusable
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test
public void testReleaseNonReusable() throws Exception {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
final CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
-1, TimeUnit.MILLISECONDS));
entry.markRouteComplete();
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(conn.isOpen()).thenReturn(Boolean.FALSE);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
Assert.assertNotNull(conn1);
Assert.assertFalse(conn1.isOpen());
mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);
Mockito.verify(pool).release(entry, false);
Mockito.verify(entry, Mockito.never()).setState(Mockito.anyObject());
Mockito.verify(entry, Mockito.never()).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestPoolingHttpClientConnectionManager.java
示例10: wrap
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
/**
* Returns a wrapped instance of {@link ConnectionRequest}
* to capture the necessary performance metrics.
*
* @param orig the target instance to be wrapped
*/
static ConnectionRequest wrap(ConnectionRequest orig) {
if (orig instanceof Wrapped) {
throw new IllegalArgumentException();
}
return (ConnectionRequest) Proxy.newProxyInstance(
// https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423
ClientConnectionRequestFactory.class.getClassLoader(),
INTERFACES,
new Handler(orig));
}
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:17,代码来源:ClientConnectionRequestFactory.java
示例11: invoke
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
Object ret = method.invoke(orig, args);
return ret instanceof ConnectionRequest
? ClientConnectionRequestFactory.wrap((ConnectionRequest) ret)
: ret
;
} catch (InvocationTargetException e) {
log.debug("", e);
throw e.getCause();
}
}
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:14,代码来源:ClientConnectionManagerFactory.java
示例12: wrap
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
/**
* Returns a wrapped instance of {@link ConnectionRequest}
* to capture the necessary performance metrics.
* @param orig the target instance to be wrapped
*/
static ConnectionRequest wrap(ConnectionRequest orig) {
if (orig instanceof Wrapped)
throw new IllegalArgumentException();
return (ConnectionRequest) Proxy.newProxyInstance(
// https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423
ClientConnectionRequestFactory.class.getClassLoader(),
interfaces,
new Handler(orig));
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:ClientConnectionRequestFactory.java
示例13: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Before
public void requestConnection() throws Exception {
HttpHost host = new HttpHost(InetAddress.getLocalHost(), inbound.getPort());
HttpRoute route = new HttpRoute(host, InetAddress.getLocalHost(), false);
connManager = new BasicHttpClientConnectionManager();
ConnectionRequest connRequest = connManager.requestConnection(route, null);
conn = connRequest.get(10, TimeUnit.SECONDS);
// Make two requests on the same connection
connManager.connect(conn, route, 10000, new BasicHttpContext());
}
开发者ID:yarpc,项目名称:yarpc-java,代码行数:11,代码来源:HttpConnectionReuseTest.java
示例14: testReleaseOnEntityConsumeContent
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@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);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestConnectionAutoRelease.java
示例15: testReleaseOnEntityWriteTo
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@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);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:37,代码来源:TestConnectionAutoRelease.java
示例16: testReleaseOnAbort
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@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);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestConnectionAutoRelease.java
示例17: getConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
private static HttpClientConnection getConnection(
final HttpClientConnectionManager mgr,
final HttpRoute route,
final long timeout,
final TimeUnit unit) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
final ConnectionRequest connRequest = mgr.requestConnection(route, null);
return connRequest.get(timeout, unit);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:9,代码来源:TestConnectionManagement.java
示例18: testSocketConnectFailureReleasesConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
/**
* Tests that if a socket fails to connect, the allocated connection is
* properly released back to the connection manager.
*/
@Test
public void testSocketConnectFailureReleasesConnection() throws Exception {
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final ConnectionRequest connrequest = Mockito.mock(ConnectionRequest.class);
Mockito.when(connrequest.get(
Mockito.anyInt(), Mockito.any(TimeUnit.class))).thenReturn(conn);
final HttpClientConnectionManager connmgr = Mockito.mock(HttpClientConnectionManager.class);
Mockito.doThrow(new ConnectException()).when(connmgr).connect(
Mockito.any(HttpClientConnection.class),
Mockito.any(HttpRoute.class),
Mockito.anyInt(),
Mockito.any(HttpContext.class));
Mockito.when(connmgr.requestConnection(
Mockito.any(HttpRoute.class), Mockito.any())).thenReturn(connrequest);
final HttpClient client = HttpClients.custom().setConnectionManager(connmgr).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("http://www.example.com/a");
try {
client.execute(httpget, context);
Assert.fail("expected IOException");
} catch(final IOException expected) {}
Mockito.verify(connmgr).releaseConnection(conn, null, 0, TimeUnit.MILLISECONDS);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:TestAbortHandling.java
示例19: requestConnection
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Override
public ConnectionRequest requestConnection(final HttpRoute route, final Object state) {
// If this is the redirect route, stub the return value
// so-as to pretend the host is waiting on a slot...
if(route.getTargetHost().getHostName().equals("localhost")) {
final Thread currentThread = Thread.currentThread();
return new ConnectionRequest() {
@Override
public boolean cancel() {
currentThread.interrupt();
return true;
}
@Override
public HttpClientConnection get(
final long timeout,
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
connLatch.countDown(); // notify waiter that we're getting a connection
// zero usually means sleep forever, but CountDownLatch doesn't interpret it that way.
if(!awaitLatch.await(timeout > 0 ? timeout : Integer.MAX_VALUE, tunit)) {
throw new ConnectionPoolTimeoutException();
}
return Mockito.mock(HttpClientConnection.class);
}
};
} else {
return super.requestConnection(route, state);
}
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:34,代码来源:TestAbortHandling.java
示例20: testLeaseReleaseReusable
import org.apache.http.conn.ConnectionRequest; //导入依赖的package包/类
@Test
public void testLeaseReleaseReusable() throws Exception {
final HttpHost target = new HttpHost("somehost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(connFactory.create(Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn1);
Mockito.verify(connFactory, Mockito.times(1)).create(
Mockito.eq(route), Mockito.<ConnectionConfig>any());
Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
mgr.releaseConnection(conn1, null, 10000, TimeUnit.MILLISECONDS);
Assert.assertEquals(route, mgr.getRoute());
Assert.assertEquals(null, mgr.getState());
final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
Assert.assertNotNull(conn2);
Assert.assertTrue(conn2.isOpen());
Mockito.verify(connFactory, Mockito.times(1)).create(
Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:30,代码来源:TestBasicHttpClientConnectionManager.java
注:本文中的org.apache.http.conn.ConnectionRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论