List of usage examples for org.apache.http.util Args notNull
public static <T> T notNull(T t, String str)
From source file:org.apache.http.impl.conn.PoolingClientConnectionManager.java
public ClientConnectionRequest 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)); }/* w w w. j a v a2 s. c om*/ final Future<HttpPoolEntry> future = this.pool.lease(route, state); return new ClientConnectionRequest() { public void abortRequest() { future.cancel(true); } public ManagedClientConnection getConnection(final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { return leaseConnection(future, timeout, tunit); } }; }
From source file:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.java
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)); }//w ww . j a v a2 s. c o m 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); } }; }
From source file:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.java
public void releaseConnection(final HttpClientConnection managedConn, final Object state, final long keepalive, final TimeUnit tunit) { Args.notNull(managedConn, "Managed connection"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.detach(managedConn); if (entry == null) { return; }/*from w w w.ja v a 2 s. co m*/ final ManagedHttpClientConnection conn = entry.getConnection(); try { if (conn.isOpen()) { entry.setState(state); entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS); if (this.log.isDebugEnabled()) { final String s; if (keepalive > 0) { s = "for " + (double) keepalive / 1000 + " seconds"; } else { s = "indefinitely"; } this.log.debug("Connection " + format(entry) + " can be kept alive " + s); } } } finally { this.pool.release(entry, conn.isOpen() && entry.isRouteComplete()); if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute())); } } } }
From source file:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.java
public void connect(final HttpClientConnection managedConn, final HttpRoute route, final int connectTimeout, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed Connection"); Args.notNull(route, "HTTP route"); final ManagedHttpClientConnection conn; synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); conn = entry.getConnection();//from w w w. j a va 2 s. com } final HttpHost host; if (route.getProxyHost() != null) { host = route.getProxyHost(); } else { host = route.getTargetHost(); } final InetSocketAddress localAddress = route.getLocalSocketAddress(); SocketConfig socketConfig = this.configData.getSocketConfig(host); if (socketConfig == null) { socketConfig = this.configData.getDefaultSocketConfig(); } if (socketConfig == null) { socketConfig = SocketConfig.DEFAULT; } this.connectionOperator.connect(conn, host, localAddress, connectTimeout, socketConfig, context); }
From source file:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.java
public void upgrade(final HttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed Connection"); Args.notNull(route, "HTTP route"); final ManagedHttpClientConnection conn; synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); conn = entry.getConnection();//from www . ja v a 2 s . c o m } this.connectionOperator.upgrade(conn, route.getTargetHost(), context); }
From source file:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.java
public void routeComplete(final HttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed Connection"); Args.notNull(route, "HTTP route"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); entry.markRouteComplete();// w ww . j a v a 2 s . c o m } }
From source file:org.apache.http.impl.conn.SingleClientConnManager.java
/** * Creates a new simple connection manager. * * @param schreg the scheme registry//from w w w.j a v a2s . c o m */ public SingleClientConnManager(final SchemeRegistry schreg) { Args.notNull(schreg, "Scheme registry"); this.schemeRegistry = schreg; this.connOperator = createConnectionOperator(schreg); this.uniquePoolEntry = new PoolEntry(); this.managedConn = null; this.lastReleaseTime = -1L; this.alwaysShutDown = false; //@@@ from params? as argument? this.isShutDown = false; }
From source file:org.apache.http.impl.conn.SingleClientConnManager.java
/** * Obtains a connection.//from w w w. j a v a 2s .co m * * @param route where the connection should point to * * @return a connection that can be used to communicate * along the given route */ public ManagedClientConnection getConnection(final HttpRoute route, final Object state) { Args.notNull(route, "Route"); assertStillUp(); if (log.isDebugEnabled()) { log.debug("Get connection for route " + route); } synchronized (this) { Asserts.check(managedConn == null, MISUSE_MESSAGE); // check re-usability of the connection boolean recreate = false; boolean shutdown = false; // Kill the connection if it expired. closeExpiredConnections(); if (uniquePoolEntry.connection.isOpen()) { final RouteTracker tracker = uniquePoolEntry.tracker; shutdown = (tracker == null || // can happen if method is aborted !tracker.toRoute().equals(route)); } else { // If the connection is not open, create a new PoolEntry, // as the connection may have been marked not reusable, // due to aborts -- and the PoolEntry should not be reused // either. There's no harm in recreating an entry if // the connection is closed. recreate = true; } if (shutdown) { recreate = true; try { uniquePoolEntry.shutdown(); } catch (final IOException iox) { log.debug("Problem shutting down connection.", iox); } } if (recreate) { uniquePoolEntry = new PoolEntry(); } managedConn = new ConnAdapter(uniquePoolEntry, route); return managedConn; } }
From source file:org.apache.http.impl.conn.SingleClientConnManager.java
public void closeIdleConnections(final long idletime, final TimeUnit tunit) { assertStillUp();// ww w . j a v a 2 s . com // idletime can be 0 or negative, no problem there Args.notNull(tunit, "Time unit"); synchronized (this) { if ((managedConn == null) && uniquePoolEntry.connection.isOpen()) { final long cutoff = System.currentTimeMillis() - tunit.toMillis(idletime); if (lastReleaseTime <= cutoff) { try { uniquePoolEntry.close(); } catch (final IOException iox) { // ignore log.debug("Problem closing idle connection.", iox); } } } } }
From source file:org.apache.http.impl.conn.tsccm.AbstractConnPool.java
/** * Closes idle connections.// w w w . ja va 2s . c o m * * @param idletime the time the connections should have been idle * in order to be closed now * @param tunit the unit for the <code>idletime</code> */ public void closeIdleConnections(final long idletime, final TimeUnit tunit) { // idletime can be 0 or negative, no problem there Args.notNull(tunit, "Time unit"); poolLock.lock(); try { idleConnHandler.closeIdleConnections(tunit.toMillis(idletime)); } finally { poolLock.unlock(); } }