Java 类org.apache.http.conn.OperatedClientConnection 实例源码

项目:purecloud-iot    文件:DefaultClientConnectionOperator.java   
@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);
}
项目:purecloud-iot    文件:BasicClientConnectionManager.java   
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;
    }
}
项目:purecloud-iot    文件:ManagedClientConnectionImpl.java   
@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;
    }
}
项目:lams    文件:DefaultClientConnectionOperator.java   
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);
}
项目:lams    文件:AbstractClientConnAdapter.java   
/**
 * 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;
}
项目:lams    文件:AbstractClientConnAdapter.java   
/**
 * 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();
    }
}
项目:lams    文件:AbstractClientConnAdapter.java   
public boolean isOpen() {
    OperatedClientConnection conn = getWrappedConnection();
    if (conn == null)
        return false;

    return conn.isOpen();
}
项目:lams    文件:AbstractClientConnAdapter.java   
public boolean isStale() {
    if (isReleased())
        return true;
    OperatedClientConnection conn = getWrappedConnection();
    if (conn == null)
        return true;

    return conn.isStale();
}
项目:lams    文件:AbstractClientConnAdapter.java   
public void receiveResponseEntity(HttpResponse response)
    throws HttpException, IOException {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.receiveResponseEntity(response);
}
项目:lams    文件:AbstractClientConnAdapter.java   
public HttpResponse receiveResponseHeader()
    throws HttpException, IOException {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    return conn.receiveResponseHeader();
}
项目:lams    文件:AbstractClientConnAdapter.java   
public void sendRequestEntity(HttpEntityEnclosingRequest request)
    throws HttpException, IOException {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.sendRequestEntity(request);
}
项目:lams    文件:AbstractClientConnAdapter.java   
public void sendRequestHeader(HttpRequest request)
    throws HttpException, IOException {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.sendRequestHeader(request);
}
项目:lams    文件:AbstractClientConnAdapter.java   
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;
}
项目:lams    文件:AbstractClientConnAdapter.java   
public Object getAttribute(final String id) {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    if (conn instanceof HttpContext) {
        return ((HttpContext) conn).getAttribute(id);
    } else {
        return null;
    }
}
项目:lams    文件:AbstractClientConnAdapter.java   
public Object removeAttribute(final String id) {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    if (conn instanceof HttpContext) {
        return ((HttpContext) conn).removeAttribute(id);
    } else {
        return null;
    }
}
项目:lams    文件:AbstractClientConnAdapter.java   
public void setAttribute(final String id, final Object obj) {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    if (conn instanceof HttpContext) {
        ((HttpContext) conn).setAttribute(id, obj);
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
private OperatedClientConnection getConnection() {
    HttpPoolEntry local = this.poolEntry;
    if (local == null) {
        return null;
    }
    return local.getConnection();
}
项目:lams    文件:ManagedClientConnectionImpl.java   
private OperatedClientConnection ensureConnection() {
    HttpPoolEntry local = this.poolEntry;
    if (local == null) {
        throw new ConnectionShutdownException();
    }
    return local.getConnection();
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public void close() throws IOException {
    HttpPoolEntry local = this.poolEntry;
    if (local != null) {
        OperatedClientConnection conn = local.getConnection();
        local.getTracker().reset();
        conn.close();
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public void shutdown() throws IOException {
    HttpPoolEntry local = this.poolEntry;
    if (local != null) {
        OperatedClientConnection conn = local.getConnection();
        local.getTracker().reset();
        conn.shutdown();
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public boolean isOpen() {
    OperatedClientConnection conn = getConnection();
    if (conn != null) {
        return conn.isOpen();
    } else {
        return false;
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public boolean isStale() {
    OperatedClientConnection conn = getConnection();
    if (conn != null) {
        return conn.isStale();
    } else {
        return true;
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public SSLSession getSSLSession() {
    OperatedClientConnection conn = ensureConnection();
    SSLSession result = null;
    Socket sock = conn.getSocket();
    if (sock instanceof SSLSocket) {
        result = ((SSLSocket)sock).getSession();
    }
    return result;
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public Object getAttribute(final String id) {
    OperatedClientConnection conn = ensureConnection();
    if (conn instanceof HttpContext) {
        return ((HttpContext) conn).getAttribute(id);
    } else {
        return null;
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
public Object removeAttribute(final String id) {
    OperatedClientConnection conn = ensureConnection();
    if (conn instanceof HttpContext) {
        return ((HttpContext) conn).removeAttribute(id);
    } else {
        return null;
    }
}
项目:lams    文件:ManagedClientConnectionImpl.java   
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;
    }
}
项目:lams    文件:ConnPoolByRoute.java   
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);
        }
    }
}
项目:lams    文件:AbstractConnPool.java   
/**
 * 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);
        }
    }
}
项目:lams    文件:AbstractPooledConnAdapter.java   
public void close() throws IOException {
    AbstractPoolEntry entry = getPoolEntry();
    if (entry != null)
        entry.shutdownEntry();

    OperatedClientConnection conn = getWrappedConnection();
    if (conn != null) {
        conn.close();
    }
}
项目:lams    文件:AbstractPooledConnAdapter.java   
public void shutdown() throws IOException {
    AbstractPoolEntry entry = getPoolEntry();
    if (entry != null)
        entry.shutdownEntry();

    OperatedClientConnection conn = getWrappedConnection();
    if (conn != null) {
        conn.shutdown();
    }
}
项目:lams    文件:HttpPoolEntry.java   
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);
}
项目:lams    文件:HttpPoolEntry.java   
@Override
public void close() {
    OperatedClientConnection conn = getConnection();
    try {
        conn.close();
    } catch (IOException ex) {
        this.log.debug("I/O error closing connection", ex);
    }
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
/**
 * 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;
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
/**
 * 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();
    }
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public boolean isOpen() {
    final OperatedClientConnection conn = getWrappedConnection();
    if (conn == null) {
        return false;
    }

    return conn.isOpen();
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public boolean isStale() {
    if (isReleased()) {
        return true;
    }
    final OperatedClientConnection conn = getWrappedConnection();
    if (conn == null) {
        return true;
    }

    return conn.isStale();
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public void receiveResponseEntity(final HttpResponse response)
    throws HttpException, IOException {
    final OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.receiveResponseEntity(response);
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public HttpResponse receiveResponseHeader()
    throws HttpException, IOException {
    final OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    return conn.receiveResponseHeader();
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public void sendRequestEntity(final HttpEntityEnclosingRequest request)
    throws HttpException, IOException {
    final OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.sendRequestEntity(request);
}
项目:purecloud-iot    文件:AbstractClientConnAdapter.java   
@Override
public void sendRequestHeader(final HttpRequest request)
    throws HttpException, IOException {
    final OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    unmarkReusable();
    conn.sendRequestHeader(request);
}