@Override public void updateSecureConnection( final OperatedClientConnection conn, final HttpHost target, final HttpContext context, final HttpParams params) throws IOException { Args.notNull(conn, "Connection"); Args.notNull(target, "Target host"); Args.notNull(params, "Parameters"); Asserts.check(conn.isOpen(), "Connection must be open"); final SchemeRegistry registry = getSchemeRegistry(context); final Scheme schm = registry.getScheme(target.getSchemeName()); Asserts.check(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory, "Socket factory must implement SchemeLayeredSocketFactory"); final SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory(); final Socket sock = lsf.createLayeredSocket( conn.getSocket(), target.getHostName(), schm.resolvePort(target.getPort()), params); prepareSocket(sock, context, params); conn.update(sock, target, lsf.isSecure(sock), params); }
ManagedClientConnection getConnection(final HttpRoute route, final Object state) { Args.notNull(route, "Route"); synchronized (this) { assertNotShutdown(); 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 opconn = this.connOperator.createConnection(); this.poolEntry = new HttpPoolEntry(this.log, id, route, opconn, 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; } }
@Override public void abortConnection() { synchronized (this) { if (this.poolEntry == null) { return; } this.reusable = false; final OperatedClientConnection conn = this.poolEntry.getConnection(); try { conn.shutdown(); } catch (final IOException ignore) { } this.manager.releaseConnection(this, this.duration, TimeUnit.MILLISECONDS); this.poolEntry = null; } }
public void updateSecureConnection( final OperatedClientConnection conn, final HttpHost target, final HttpContext context, final HttpParams params) throws IOException { if (conn == null) { throw new IllegalArgumentException("Connection may not be null"); } if (target == null) { throw new IllegalArgumentException("Target host may not be null"); } if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } if (!conn.isOpen()) { throw new IllegalStateException("Connection must be open"); } final Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) { throw new IllegalArgumentException ("Target scheme (" + schm.getName() + ") must have layered socket factory."); } SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory(); Socket sock; try { sock = lsf.createLayeredSocket( conn.getSocket(), target.getHostName(), target.getPort(), params); } catch (ConnectException ex) { throw new HttpHostConnectException(target, ex); } prepareSocket(sock, context, params); conn.update(sock, target, lsf.isSecure(sock), params); }
/** * Creates a new connection adapter. * The adapter is initially <i>not</i> * {@link #isMarkedReusable marked} as reusable. * * @param mgr the connection manager, or <code>null</code> * @param conn the connection to wrap, or <code>null</code> */ protected AbstractClientConnAdapter(ClientConnectionManager mgr, OperatedClientConnection conn) { super(); connManager = mgr; wrappedConnection = conn; markedReusable = false; released = false; duration = Long.MAX_VALUE; }
/** * Asserts that there is a valid wrapped connection to delegate to. * * @throws ConnectionShutdownException if there is no wrapped connection * or connection has been aborted */ protected final void assertValid( final OperatedClientConnection wrappedConn) throws ConnectionShutdownException { if (isReleased() || wrappedConn == null) { throw new ConnectionShutdownException(); } }
public boolean isOpen() { OperatedClientConnection conn = getWrappedConnection(); if (conn == null) return false; return conn.isOpen(); }
public boolean isStale() { if (isReleased()) return true; OperatedClientConnection conn = getWrappedConnection(); if (conn == null) return true; return conn.isStale(); }
public void receiveResponseEntity(HttpResponse response) throws HttpException, IOException { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.receiveResponseEntity(response); }
public HttpResponse receiveResponseHeader() throws HttpException, IOException { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); return conn.receiveResponseHeader(); }
public void sendRequestEntity(HttpEntityEnclosingRequest request) throws HttpException, IOException { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.sendRequestEntity(request); }
public void sendRequestHeader(HttpRequest request) throws HttpException, IOException { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.sendRequestHeader(request); }
public SSLSession getSSLSession() { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (!isOpen()) return null; SSLSession result = null; Socket sock = conn.getSocket(); if (sock instanceof SSLSocket) { result = ((SSLSocket)sock).getSession(); } return result; }
public Object getAttribute(final String id) { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (conn instanceof HttpContext) { return ((HttpContext) conn).getAttribute(id); } else { return null; } }
public Object removeAttribute(final String id) { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (conn instanceof HttpContext) { return ((HttpContext) conn).removeAttribute(id); } else { return null; } }
public void setAttribute(final String id, final Object obj) { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (conn instanceof HttpContext) { ((HttpContext) conn).setAttribute(id, obj); } }
private OperatedClientConnection getConnection() { HttpPoolEntry local = this.poolEntry; if (local == null) { return null; } return local.getConnection(); }
private OperatedClientConnection ensureConnection() { HttpPoolEntry local = this.poolEntry; if (local == null) { throw new ConnectionShutdownException(); } return local.getConnection(); }
public void close() throws IOException { HttpPoolEntry local = this.poolEntry; if (local != null) { OperatedClientConnection conn = local.getConnection(); local.getTracker().reset(); conn.close(); } }
public void shutdown() throws IOException { HttpPoolEntry local = this.poolEntry; if (local != null) { OperatedClientConnection conn = local.getConnection(); local.getTracker().reset(); conn.shutdown(); } }
public boolean isOpen() { OperatedClientConnection conn = getConnection(); if (conn != null) { return conn.isOpen(); } else { return false; } }
public boolean isStale() { OperatedClientConnection conn = getConnection(); if (conn != null) { return conn.isStale(); } else { return true; } }
public SSLSession getSSLSession() { OperatedClientConnection conn = ensureConnection(); SSLSession result = null; Socket sock = conn.getSocket(); if (sock instanceof SSLSocket) { result = ((SSLSocket)sock).getSession(); } return result; }
public Object getAttribute(final String id) { OperatedClientConnection conn = ensureConnection(); if (conn instanceof HttpContext) { return ((HttpContext) conn).getAttribute(id); } else { return null; } }
public Object removeAttribute(final String id) { OperatedClientConnection conn = ensureConnection(); if (conn instanceof HttpContext) { return ((HttpContext) conn).removeAttribute(id); } else { return null; } }
public void abortConnection() { synchronized (this) { if (this.poolEntry == null) { return; } this.reusable = false; OperatedClientConnection conn = this.poolEntry.getConnection(); try { conn.shutdown(); } catch (IOException ignore) { } this.manager.releaseConnection(this, this.duration, TimeUnit.MILLISECONDS); this.poolEntry = null; } }
private void closeConnection(final BasicPoolEntry entry) { OperatedClientConnection conn = entry.getConnection(); if (conn != null) { try { conn.close(); } catch (IOException ex) { log.debug("I/O error closing connection", ex); } } }
/** * Closes a connection from this pool. * * @param conn the connection to close, or <code>null</code> */ protected void closeConnection(final OperatedClientConnection conn) { if (conn != null) { try { conn.close(); } catch (IOException ex) { log.debug("I/O error closing connection", ex); } } }
public void close() throws IOException { AbstractPoolEntry entry = getPoolEntry(); if (entry != null) entry.shutdownEntry(); OperatedClientConnection conn = getWrappedConnection(); if (conn != null) { conn.close(); } }
public void shutdown() throws IOException { AbstractPoolEntry entry = getPoolEntry(); if (entry != null) entry.shutdownEntry(); OperatedClientConnection conn = getWrappedConnection(); if (conn != null) { conn.shutdown(); } }
public HttpPoolEntry( final Log log, final String id, final HttpRoute route, final OperatedClientConnection conn, final long timeToLive, final TimeUnit tunit) { super(id, route, conn, timeToLive, tunit); this.log = log; this.tracker = new RouteTracker(route); }
@Override public void close() { OperatedClientConnection conn = getConnection(); try { conn.close(); } catch (IOException ex) { this.log.debug("I/O error closing connection", ex); } }
/** * Creates a new connection adapter. * The adapter is initially <i>not</i> * {@link #isMarkedReusable marked} as reusable. * * @param mgr the connection manager, or {@code null} * @param conn the connection to wrap, or {@code null} */ protected AbstractClientConnAdapter(final ClientConnectionManager mgr, final OperatedClientConnection conn) { super(); connManager = mgr; wrappedConnection = conn; markedReusable = false; released = false; duration = Long.MAX_VALUE; }
@Override public boolean isOpen() { final OperatedClientConnection conn = getWrappedConnection(); if (conn == null) { return false; } return conn.isOpen(); }
@Override public boolean isStale() { if (isReleased()) { return true; } final OperatedClientConnection conn = getWrappedConnection(); if (conn == null) { return true; } return conn.isStale(); }
@Override public void receiveResponseEntity(final HttpResponse response) throws HttpException, IOException { final OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.receiveResponseEntity(response); }
@Override public HttpResponse receiveResponseHeader() throws HttpException, IOException { final OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); return conn.receiveResponseHeader(); }
@Override public void sendRequestEntity(final HttpEntityEnclosingRequest request) throws HttpException, IOException { final OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.sendRequestEntity(request); }
@Override public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException { final OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); unmarkReusable(); conn.sendRequestHeader(request); }