List of usage examples for org.apache.http.impl.conn ManagedClientConnectionImpl ManagedClientConnectionImpl
ManagedClientConnectionImpl(final ClientConnectionManager manager, final ClientConnectionOperator operator, final HttpPoolEntry entry)
From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java
ManagedClientConnection getConnection(final HttpRoute route, final Object state) { Args.notNull(route, "Route"); synchronized (this) { assertNotShutdown();//from w w w . jav a 2s . co m if (this.log.isDebugEnabled()) { this.log.debug("Get connection for route " + route); } Asserts.check(this.conn == null, MISUSE_MESSAGE); if (this.poolEntry != null && !this.poolEntry.getPlannedRoute().equals(route)) { this.poolEntry.close(); this.poolEntry = null; } if (this.poolEntry == null) { final String id = Long.toString(COUNTER.getAndIncrement()); final OperatedClientConnection conn = this.connOperator.createConnection(); this.poolEntry = new HttpPoolEntry(this.log, id, route, conn, 0, TimeUnit.MILLISECONDS); } final long now = System.currentTimeMillis(); if (this.poolEntry.isExpired(now)) { this.poolEntry.close(); this.poolEntry.getTracker().reset(); } this.conn = new ManagedClientConnectionImpl(this, this.connOperator, this.poolEntry); return this.conn; } }
From source file:org.apache.http.impl.conn.FixedPoolingClientConnectionManager.java
ManagedClientConnection leaseConnection(final Future<HttpPoolEntry> future, final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { HttpPoolEntry entry;/* w w w . j a va 2 s. c o m*/ try { entry = future.get(timeout, tunit); if (entry == null || future.isCancelled()) { throw new InterruptedException(); } if (entry.getConnection() == null) { throw new IllegalStateException("Pool entry with no connection"); } if (this.log.isDebugEnabled()) { this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return new ManagedClientConnectionImpl(this, this.operator, entry); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); if (cause == null) { cause = ex; } this.log.error("Unexpected exception leasing connection from pool", cause); // Should never happen throw new InterruptedException(); } catch (TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection"); } }
From source file:org.apache.http.impl.conn.JMeterPoolingClientConnectionManager.java
ManagedClientConnection leaseConnection(final Future<HttpPoolEntry> future, final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { final HttpPoolEntry entry; try {/*from ww w .j av a 2 s . c om*/ entry = future.get(timeout, tunit); if (entry == null || future.isCancelled()) { throw new InterruptedException(); } Asserts.check(entry.getConnection() != null, "Pool entry with no connection"); if (this.log.isDebugEnabled()) { this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return new ManagedClientConnectionImpl(this, this.operator, entry); } catch (final ExecutionException ex) { Throwable cause = ex.getCause(); if (cause == null) { cause = ex; } this.log.error("Unexpected exception leasing connection from pool", cause); // Should never happen throw new InterruptedException(); } catch (final TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool"); } }