本文整理汇总了Java中org.apache.http.conn.ConnectionRequest类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionRequest类的具体用法?Java ConnectionRequest怎么用?Java ConnectionRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionRequest类属于org.apache.http.conn包,在下文中一共展示了ConnectionRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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());
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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();
}
}
示例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));
}
示例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());
}
示例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);
}
示例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);
}