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.nio.conn.PoolingClientAsyncConnectionManager.java
@Override public Future<ManagedClientAsyncConnection> leaseConnection(final HttpRoute route, final Object state, final long connectTimeout, final TimeUnit tunit, final FutureCallback<ManagedClientAsyncConnection> callback) { Args.notNull(route, "HTTP route"); Args.notNull(tunit, "Time unit"); if (this.log.isDebugEnabled()) { this.log.debug("Connection request: " + format(route, state) + formatStats(route)); }/*from ww w .j av a 2 s .c om*/ final BasicFuture<ManagedClientAsyncConnection> future = new BasicFuture<ManagedClientAsyncConnection>( callback); this.pool.lease(route, state, connectTimeout, tunit, new InternalPoolEntryCallback(future)); return future; }
From source file:org.apache.http.impl.nio.conn.PoolingClientAsyncConnectionManager.java
@Override public void releaseConnection(final ManagedClientAsyncConnection conn, final long keepalive, final TimeUnit tunit) { Args.notNull(conn, "HTTP connection"); if (!(conn instanceof ManagedClientAsyncConnectionImpl)) { throw new IllegalArgumentException( "Connection class mismatch, " + "connection not obtained from this manager"); }/*ww w.j a v a 2 s. com*/ Args.notNull(tunit, "Time unit"); final ManagedClientAsyncConnectionImpl managedConn = (ManagedClientAsyncConnectionImpl) conn; final ClientAsyncConnectionManager manager = managedConn.getManager(); if (manager != null && manager != this) { throw new IllegalArgumentException("Connection not obtained from this manager"); } if (this.pool.isShutdown()) { return; } synchronized (managedConn) { final HttpPoolEntry entry = managedConn.getPoolEntry(); if (entry == null) { return; } try { if (managedConn.isOpen() && !managedConn.isMarkedReusable()) { try { managedConn.shutdown(); } catch (final IOException iox) { if (this.log.isDebugEnabled()) { this.log.debug("I/O exception shutting down released connection", iox); } } } if (managedConn.isOpen()) { entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS); if (this.log.isDebugEnabled()) { String s; if (keepalive > 0) { s = "for " + keepalive + " " + tunit; } else { s = "indefinitely"; } this.log.debug("Connection " + format(entry) + " can be kept alive " + s); } // Do not time out pooled connection managedConn.setSocketTimeout(0); } } finally { this.pool.release(managedConn.detach(), managedConn.isMarkedReusable()); } if (this.log.isDebugEnabled()) { this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute())); } } }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
public PoolingNHttpClientConnectionManager(final ConnectingIOReactor ioreactor, final NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, final Registry<SchemeIOSessionStrategy> iosessionFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit tunit) { super();//from w w w . j a v a2s . com Args.notNull(ioreactor, "I/O reactor"); Args.notNull(iosessionFactoryRegistry, "I/O session factory registry"); this.ioreactor = ioreactor; this.configData = new ConfigData(); this.pool = new CPool(ioreactor, new InternalConnectionFactory(this.configData, connFactory), new InternalAddressResolver(schemePortResolver, dnsResolver), 2, 20, timeToLive, tunit != null ? tunit : TimeUnit.MILLISECONDS); this.iosessionFactoryRegistry = iosessionFactoryRegistry; }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public Future<NHttpClientConnection> requestConnection(final HttpRoute route, final Object state, final long connectTimeout, final long leaseTimeout, final TimeUnit tunit, final FutureCallback<NHttpClientConnection> callback) { Args.notNull(route, "HTTP route"); if (this.log.isDebugEnabled()) { this.log.debug("Connection request: " + format(route, state) + formatStats(route)); }/*from w w w .jav a 2 s. com*/ final BasicFuture<NHttpClientConnection> future = new BasicFuture<NHttpClientConnection>(callback); final HttpHost host; if (route.getProxyHost() != null) { host = route.getProxyHost(); } else { host = route.getTargetHost(); } final SchemeIOSessionStrategy sf = this.iosessionFactoryRegistry.lookup(host.getSchemeName()); if (sf == null) { future.failed(new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported")); return future; } this.pool.lease(route, state, connectTimeout, leaseTimeout, tunit != null ? tunit : TimeUnit.MILLISECONDS, new InternalPoolEntryCallback(future)); return future; }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public void releaseConnection(final NHttpClientConnection 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; }//ww w .j a v a 2 s .c om if (this.log.isDebugEnabled()) { this.log.debug("Releasing connection: " + format(entry) + formatStats(entry.getRoute())); } final NHttpClientConnection 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.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public void startRoute(final NHttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed connection"); Args.notNull(route, "HTTP route"); final HttpHost host; if (route.getProxyHost() != null) { host = route.getProxyHost();// ww w .j a v a 2s .c o m } else { host = route.getTargetHost(); } final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context); final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName()); if (sf == null) { throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported"); } if (sf.isLayeringRequired()) { synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); final ManagedNHttpClientConnection conn = entry.getConnection(); final IOSession ioSession = conn.getIOSession(); final IOSession currentSession = sf.upgrade(host, ioSession); conn.bind(currentSession); } } }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public void upgrade(final NHttpClientConnection managedConn, final HttpRoute route, final HttpContext context) throws IOException { Args.notNull(managedConn, "Managed connection"); Args.notNull(route, "HTTP route"); final HttpHost host = route.getTargetHost(); final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context); final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName()); if (sf == null) { throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported"); }//from www. j a v a2 s. co m if (!sf.isLayeringRequired()) { throw new UnsupportedSchemeException( host.getSchemeName() + " protocol does not support connection upgrade"); } synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); final ManagedNHttpClientConnection conn = entry.getConnection(); final IOSession currentSession = sf.upgrade(host, conn.getIOSession()); conn.bind(currentSession); } }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public void routeComplete(final NHttpClientConnection managedConn, final HttpRoute route, final HttpContext context) { Args.notNull(managedConn, "Managed connection"); Args.notNull(route, "HTTP route"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); entry.markRouteComplete();/*from w ww.j a v a2 s . c o m*/ } }
From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java
@Override public boolean isRouteComplete(final NHttpClientConnection managedConn) { Args.notNull(managedConn, "Managed connection"); synchronized (managedConn) { final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn); return entry.isRouteComplete(); }//www . j ava 2s .c o m }