Example usage for org.apache.http.nio.conn ManagedNHttpClientConnection getIOSession

List of usage examples for org.apache.http.nio.conn ManagedNHttpClientConnection getIOSession

Introduction

In this page you can find the example usage for org.apache.http.nio.conn ManagedNHttpClientConnection getIOSession.

Prototype

IOSession getIOSession();

Source Link

Document

Returns the underlying I/O session.

Usage

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();//from ww  w . j  ava 2 s  . co  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 w  w w  . ja  v  a 2  s  .c o 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);
    }
}