public final ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { return new ClientConnectionRequest() { public void abortRequest() { // Nothing to abort, since requests are immediate. } public ManagedClientConnection getConnection( long timeout, TimeUnit tunit) { return BasicClientConnectionManager.this.getConnection( route, state); } }; }
public final ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { return new ClientConnectionRequest() { public void abortRequest() { // Nothing to abort, since requests are immediate. } public ManagedClientConnection getConnection( long timeout, TimeUnit tunit) { return SingleClientConnManager.this.getConnection( route, state); } }; }
public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { if (route == null) { throw new IllegalArgumentException("HTTP route may not be null"); } if (this.log.isDebugEnabled()) { this.log.debug("Connection request: " + format(route, state) + formatStats(route)); } 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); } }; }
@Override 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)); } final Future<HttpPoolEntry> future = this.pool.lease(route, state); return new ClientConnectionRequest() { @Override public void abortRequest() { future.cancel(true); } @Override public ManagedClientConnection getConnection( final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { return leaseConnection(future, timeout, tunit); } }; }
@Override public final ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { return new ClientConnectionRequest() { @Override public void abortRequest() { // Nothing to abort, since requests are immediate. } @Override public ManagedClientConnection getConnection( final long timeout, final TimeUnit tunit) { return BasicClientConnectionManager.this.getConnection( route, state); } }; }
@Override public final ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { return new ClientConnectionRequest() { @Override public void abortRequest() { // Nothing to abort, since requests are immediate. } @Override public ManagedClientConnection getConnection( final long timeout, final TimeUnit tunit) { return SingleClientConnManager.this.getConnection( route, state); } }; }
public final ClientConnectionRequest requestConnection(final HttpRoute paramHttpRoute, Object paramObject) { new ClientConnectionRequest() { public final void abortRequest() { this.val$poolRequest.abortRequest(); } public final ManagedClientConnection getConnection(long paramAnonymousLong, TimeUnit paramAnonymousTimeUnit) throws InterruptedException, ConnectionPoolTimeoutException { if (paramHttpRoute == null) { throw new IllegalArgumentException("Route may not be null."); } BasicPoolEntry localBasicPoolEntry = this.val$poolRequest.getPoolEntry(paramAnonymousLong, paramAnonymousTimeUnit); return new ElegantThreadSafeConnManager.ElegantBasicPooledConnAdapter(ElegantThreadSafeConnManager.this, localBasicPoolEntry); } }; }
public ClientConnectionRequest requestConnection(HttpRoute route, Object state) { if (count > MAX_COUNT) { LOG.log(Level.INFO, "****Getting connection in pool. Current total max = " + getConnectionsInPool() + " Current for route = " + getConnectionsInPool(route) + " Route = " + route.getTargetHost()); count = 0; } ++count; return super.requestConnection(route, state); }
public void setConnectionRequest(final ClientConnectionRequest connRequest) throws IOException { if (this.aborted) { throw new IOException("Request already aborted"); } this.abortLock.lock(); try { this.connRequest = connRequest; } finally { this.abortLock.unlock(); } }
public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { final PoolEntryRequest poolRequest = pool.requestPoolEntry( route, state); return new ClientConnectionRequest() { public void abortRequest() { poolRequest.abortRequest(); } public ManagedClientConnection getConnection( long timeout, TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { if (route == null) { throw new IllegalArgumentException("Route may not be null."); } if (log.isDebugEnabled()) { log.debug("Get connection: " + route + ", timeout = " + timeout); } BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit); return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry); } }; }
@Deprecated public void setConnectionRequest(final ClientConnectionRequest connRequest) { setCancellable(new Cancellable() { public boolean cancel() { connRequest.abortRequest(); return true; } }); }
public ClientConnectionManager getConnectionManager() { return new ClientConnectionManager() { public void shutdown() { connManager.shutdown(); } public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { throw new UnsupportedOperationException(); } public void releaseConnection( final ManagedClientConnection conn, final long validDuration, final TimeUnit timeUnit) { throw new UnsupportedOperationException(); } public SchemeRegistry getSchemeRegistry() { throw new UnsupportedOperationException(); } public void closeIdleConnections(final long idletime, final TimeUnit tunit) { connManager.closeIdleConnections(idletime, tunit); } public void closeExpiredConnections() { connManager.closeExpiredConnections(); } }; }
/** * Returns a wrapped instance of {@link ClientConnectionRequest} * to capture the necessary performance metrics. * @param orig the target instance to be wrapped */ static ClientConnectionRequest wrap(ClientConnectionRequest orig) { if (orig instanceof Wrapped) throw new IllegalArgumentException(); return (ClientConnectionRequest) Proxy.newProxyInstance( // https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423 ClientConnectionRequestFactory.class.getClassLoader(), interfaces, new Handler(orig)); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { Object ret = method.invoke(orig, args); return ret instanceof ClientConnectionRequest ? ClientConnectionRequestFactory.wrap((ClientConnectionRequest) ret) : ret ; } catch (InvocationTargetException e) { log.debug("", e); throw e.getCause(); } }
@Override public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { final PoolEntryRequest poolRequest = pool.requestPoolEntry( route, state); return new ClientConnectionRequest() { @Override public void abortRequest() { poolRequest.abortRequest(); } @Override public ManagedClientConnection getConnection( final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { Args.notNull(route, "Route"); if (log.isDebugEnabled()) { log.debug("Get connection: " + route + ", timeout = " + timeout); } final BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit); return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry); } }; }
@Override @Deprecated public void setConnectionRequest(final ClientConnectionRequest connRequest) { setCancellable(new Cancellable() { @Override public boolean cancel() { connRequest.abortRequest(); return true; } }); }
public void setConnectionRequest(final ClientConnectionRequest connRequest) throws IOException { this.abortLock.lock(); try { if (this.aborted) { throw new IOException("Request already aborted"); } this.releaseTrigger = null; this.connRequest = connRequest; } finally { this.abortLock.unlock(); } }
public void abort() { ClientConnectionRequest localRequest; ConnectionReleaseTrigger localTrigger; this.abortLock.lock(); try { if (this.aborted) { return; } this.aborted = true; localRequest = connRequest; localTrigger = releaseTrigger; } finally { this.abortLock.unlock(); } // Trigger the callbacks outside of the lock, to prevent // deadlocks in the scenario where the callbacks have // their own locks that may be used while calling // setReleaseTrigger or setConnectionRequest. if (localRequest != null) { localRequest.abortRequest(); } if (localTrigger != null) { try { localTrigger.abortConnection(); } catch (IOException ex) { // ignore } } }
public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { final PoolEntryRequest poolRequest = connectionPool.requestPoolEntry( route, state); return new ClientConnectionRequest() { public void abortRequest() { poolRequest.abortRequest(); } public ManagedClientConnection getConnection( long timeout, TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { if (route == null) { throw new IllegalArgumentException("Route may not be null."); } if (log.isDebugEnabled()) { log.debug("Get connection: " + route + ", timeout = " + timeout); } BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit); return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry); } }; }
/** * Main entry point to this example. * * @param args ignored */ public final static void main(String[] args) throws Exception { final HttpHost target = new HttpHost("jakarta.apache.org", 80, "http"); setup(); // some general setup ClientConnectionManager clcm = createManager(); HttpRequest req = createRequest(target); HttpContext ctx = createContext(); System.out.println("preparing route to " + target); HttpRoute route = new HttpRoute (target, null, supportedSchemes.getScheme(target).isLayered()); System.out.println("requesting connection for " + route); ClientConnectionRequest connRequest = clcm.requestConnection(route, null); ManagedClientConnection conn = connRequest.getConnection(0, null); try { System.out.println("opening connection"); conn.open(route, ctx, getParams()); System.out.println("sending request"); conn.sendRequestHeader(req); // there is no request entity conn.flush(); System.out.println("receiving response header"); HttpResponse rsp = conn.receiveResponseHeader(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i=0; i<headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); System.out.println("closing connection"); conn.close(); } finally { if (conn.isOpen()) { System.out.println("shutting down connection"); try { conn.shutdown(); } catch (Exception x) { System.out.println("problem during shutdown"); x.printStackTrace(System.out); } } System.out.println("releasing connection"); clcm.releaseConnection(conn, -1, null); } }
Handler(ClientConnectionRequest orig) { this.orig = orig; }
@Override public ClientConnectionRequest requestConnection(final HttpRoute route, final Object state) { ClientConnectionRequest res = super.requestConnection(route, state); return new MeasuringConnectionRequest(res); }
public MeasuringConnectionRequest(ClientConnectionRequest res) { handler = res; }
@Override public ClientConnectionManager getConnectionManager() { return new ClientConnectionManager() { @Override public void shutdown() { connManager.shutdown(); } @Override public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { throw new UnsupportedOperationException(); } @Override public void releaseConnection( final ManagedClientConnection conn, final long validDuration, final TimeUnit timeUnit) { throw new UnsupportedOperationException(); } @Override public SchemeRegistry getSchemeRegistry() { throw new UnsupportedOperationException(); } @Override public void closeIdleConnections(final long idletime, final TimeUnit tunit) { connManager.closeIdleConnections(idletime, tunit); } @Override public void closeExpiredConnections() { connManager.closeExpiredConnections(); } }; }
public final ClientConnectionRequest requestConnection(HttpRoute paramHttpRoute, Object paramObject) { return new jsk(this, super.requestConnection(paramHttpRoute, paramObject)); }
@Override public ClientConnectionRequest requestConnection(HttpRoute route, Object state) { // TODO Auto-generated method stub return super.requestConnection(route, state); }
@Override public ClientConnectionRequest requestConnection(HttpRoute route, Object state) { IdleConnectionCloserThread.ensureRunning(this, KEEP_ALIVE_DURATION_SECS, KEEP_ALIVE_MONITOR_INTERVAL_SECS); return super.requestConnection(route, state); }
/** * Sets the {@link ClientConnectionRequest} callback that can be * used to abort a long-lived request for a connection. * If the request is already aborted, throws an {@link IOException}. * * @see ClientConnectionManager */ void setConnectionRequest(ClientConnectionRequest connRequest) throws IOException;
/** * Sets the {@link org.apache.http.conn.ClientConnectionRequest} * callback that can be used to abort a long-lived request for a connection. * If the request is already aborted, throws an {@link IOException}. * * @see org.apache.http.conn.ClientConnectionManager */ void setConnectionRequest(ClientConnectionRequest connRequest) throws IOException;