List of usage examples for org.apache.http.util Asserts check
public static void check(boolean z, String str)
From source file:org.apache.http.impl.conn.tsccm.RouteSpecificPool.java
/** * Forgets about an entry from this pool. * This method is used to indicate that an entry * {@link #allocEntry allocated}//from w ww. ja v a 2 s . c o m * from this pool has been lost and will not be returned. */ public void dropEntry() { Asserts.check(numEntries > 0, "There is no entry that could be dropped"); numEntries--; }
From source file:org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.java
public void releaseConnection(final ManagedClientConnection conn, final long validDuration, final TimeUnit timeUnit) { Args.check(conn instanceof BasicPooledConnAdapter, "Connection class mismatch, " + "connection not obtained from this manager"); final BasicPooledConnAdapter hca = (BasicPooledConnAdapter) conn; if (hca.getPoolEntry() != null) { Asserts.check(hca.getManager() == this, "Connection not obtained from this manager"); }/* w ww . j a va 2 s. co m*/ synchronized (hca) { final BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry(); if (entry == null) { return; } try { // make sure that the response has been read completely if (hca.isOpen() && !hca.isMarkedReusable()) { // In MTHCM, there would be a call to // SimpleHttpConnectionManager.finishLastResponse(conn); // Consuming the response is handled outside in 4.0. // make sure this connection will not be re-used // Shut down rather than close, we might have gotten here // because of a shutdown trigger. // Shutdown of the adapter also clears the tracked route. hca.shutdown(); } } catch (final IOException iox) { if (log.isDebugEnabled()) { log.debug("Exception shutting down released connection.", iox); } } finally { final boolean reusable = hca.isMarkedReusable(); if (log.isDebugEnabled()) { if (reusable) { log.debug("Released connection is reusable."); } else { log.debug("Released connection is not reusable."); } } hca.detach(); pool.freeEntry(entry, reusable, validDuration, timeUnit); } } }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void verifytRoute() { if (!this.routeEstablished.get() && this.routeTrackerRef.get() == null) { final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final boolean routeComplete = this.connmgr.isRouteComplete(managedConn); this.routeEstablished.set(routeComplete); if (!routeComplete) { this.log.debug("Start connection routing"); final HttpRoute route = this.routeRef.get(); this.routeTrackerRef.set(new RouteTracker(route)); } else {/* www . j a v a 2 s.co m*/ this.log.debug("Connection route already established"); } } }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void onRouteToTarget() throws IOException { final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final HttpRoute route = this.routeRef.get(); Asserts.check(route != null, "Inconsistent state: HTTP route is null"); final RouteTracker routeTracker = this.routeTrackerRef.get(); Asserts.check(routeTracker != null, "Inconsistent state: HTTP route tracker"); this.connmgr.startRoute(managedConn, route, this.localContext); routeTracker.connectTarget(route.isSecure()); }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void onRouteToProxy() throws IOException { final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final HttpRoute route = this.routeRef.get(); Asserts.check(route != null, "Inconsistent state: HTTP route is null"); final RouteTracker routeTracker = this.routeTrackerRef.get(); Asserts.check(routeTracker != null, "Inconsistent state: HTTP route tracker"); this.connmgr.startRoute(managedConn, route, this.localContext); final HttpHost proxy = route.getProxyHost(); routeTracker.connectProxy(proxy, false); }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void onRouteUpgrade() throws IOException { final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final HttpRoute route = this.routeRef.get(); Asserts.check(route != null, "Inconsistent state: HTTP route is null"); final RouteTracker routeTracker = this.routeTrackerRef.get(); Asserts.check(routeTracker != null, "Inconsistent state: HTTP route tracker"); this.connmgr.upgrade(managedConn, route, this.localContext); routeTracker.layerProtocol(route.isSecure()); }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void onRouteTunnelToTarget() { final RouteTracker routeTracker = this.routeTrackerRef.get(); Asserts.check(routeTracker != null, "Inconsistent state: HTTP route tracker"); routeTracker.tunnelTarget(false);//from w w w . j a v a 2s. c o m }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final void onRouteComplete() { final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final HttpRoute route = this.routeRef.get(); Asserts.check(route != null, "Inconsistent state: HTTP route is null"); this.connmgr.routeComplete(managedConn, route, this.localContext); this.routeEstablished.set(true); this.routeTrackerRef.set(null); }
From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java
final boolean manageConnectionPersistence() { final HttpResponse response = this.responseRef.get(); Asserts.check(response != null, "Inconsistent state: HTTP response"); final NHttpClientConnection managedConn = this.managedConnRef.get(); Asserts.check(managedConn != null, "Inconsistent state: managed connection is null"); final boolean keepAlive = managedConn.isOpen() && this.connReuseStrategy.keepAlive(response, this.localContext); if (keepAlive) { final long validDuration = this.keepaliveStrategy.getKeepAliveDuration(response, this.localContext); if (this.log.isDebugEnabled()) { final String s; if (validDuration > 0) { s = "for " + validDuration + " " + TimeUnit.MILLISECONDS; } else { s = "indefinitely"; }//from w w w . ja v a 2 s . c om this.log.debug("[exchange: " + this.id + "] Connection can be kept alive " + s); } this.validDurationRef.set(validDuration); } else { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Connection cannot be kept alive"); } this.validDurationRef.set(null); } return keepAlive; }
From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java
@Override public HttpRequest generateRequest() throws IOException, HttpException { verifytRoute();/*from ww w.j ava2s . c o m*/ if (!isRouteEstablished()) { onRouteToTarget(); onRouteComplete(); } final NHttpClientConnection localConn = getConnection(); this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, localConn); Asserts.check(this.requestProducerRef.get() == null, "Inconsistent state: currentRequest producer is not null"); final HttpAsyncRequestProducer requestProducer = this.requestProducerQueue.poll(); if (requestProducer == null) { return null; } this.requestProducerRef.set(requestProducer); final HttpRequest original = requestProducer.generateRequest(); final HttpRequestWrapper currentRequest = HttpRequestWrapper.wrap(original); final RequestConfig config = this.localContext.getRequestConfig(); if (config.getSocketTimeout() > 0) { localConn.setSocketTimeout(config.getSocketTimeout()); } this.httpProcessor.process(currentRequest, this.localContext); this.requestQueue.add(currentRequest); setCurrentRequest(currentRequest); return currentRequest; }