Search in sources :

Example 1 with RouteTracker

use of org.apache.http.conn.routing.RouteTracker in project robovm by robovm.

the class AbstractPoolEntry method open.

/**
     * Opens the underlying connection.
     *
     * @param route         the route along which to open the connection
     * @param context       the context for opening the connection
     * @param params        the parameters for opening the connection
     *
     * @throws IOException  in case of a problem
     */
public void open(HttpRoute route, HttpContext context, HttpParams params) throws IOException {
    if (route == null) {
        throw new IllegalArgumentException("Route must not be null.");
    }
    //@@@ is context allowed to be null? depends on operator?
    if (params == null) {
        throw new IllegalArgumentException("Parameters must not be null.");
    }
    if ((this.tracker != null) && this.tracker.isConnected()) {
        throw new IllegalStateException("Connection already open.");
    }
    // - collect the arguments
    // - call the operator
    // - update the tracking data
    // In this order, we can be sure that only a successful
    // opening of the connection will be tracked.
    //@@@ verify route against planned route?
    this.tracker = new RouteTracker(route);
    final HttpHost proxy = route.getProxyHost();
    connOperator.openConnection(this.connection, (proxy != null) ? proxy : route.getTargetHost(), route.getLocalAddress(), context, params);
    // capture volatile        
    RouteTracker localTracker = tracker;
    // fail early.
    if (localTracker == null) {
        throw new IOException("Request aborted");
    }
    if (proxy == null) {
        localTracker.connectTarget(this.connection.isSecure());
    } else {
        localTracker.connectProxy(proxy, this.connection.isSecure());
    }
}
Also used : HttpHost(org.apache.http.HttpHost) IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker)

Example 2 with RouteTracker

use of org.apache.http.conn.routing.RouteTracker in project robovm by robovm.

the class SingleClientConnManager method getConnection.

/**
     * Obtains a connection.
     * This method does not block.
     *
     * @param route     where the connection should point to
     *
     * @return  a connection that can be used to communicate
     *          along the given route
     */
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
    if (route == null) {
        throw new IllegalArgumentException("Route may not be null.");
    }
    assertStillUp();
    if (log.isDebugEnabled()) {
        log.debug("Get connection for route " + route);
    }
    if (managedConn != null)
        revokeConnection();
    // check re-usability of the connection
    boolean recreate = false;
    boolean shutdown = false;
    // Kill the connection if it expired.
    closeExpiredConnections();
    if (uniquePoolEntry.connection.isOpen()) {
        RouteTracker tracker = uniquePoolEntry.tracker;
        shutdown = (// can happen if method is aborted
        tracker == null || !tracker.toRoute().equals(route));
    } else {
        // If the connection is not open, create a new PoolEntry,
        // as the connection may have been marked not reusable,
        // due to aborts -- and the PoolEntry should not be reused
        // either.  There's no harm in recreating an entry if
        // the connection is closed.
        recreate = true;
    }
    if (shutdown) {
        recreate = true;
        try {
            uniquePoolEntry.shutdown();
        } catch (IOException iox) {
            log.debug("Problem shutting down connection.", iox);
        }
    }
    if (recreate)
        uniquePoolEntry = new PoolEntry();
    // updated statistics options.
    try {
        final Socket socket = uniquePoolEntry.connection.getSocket();
        if (socket != null) {
            SocketTagger.get().tag(socket);
        }
    } catch (IOException iox) {
        log.debug("Problem tagging socket.", iox);
    }
    // END android-changed
    managedConn = new ConnAdapter(uniquePoolEntry, route);
    return managedConn;
}
Also used : IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker) Socket(java.net.Socket)

Example 3 with RouteTracker

use of org.apache.http.conn.routing.RouteTracker in project XobotOS by xamarin.

the class SingleClientConnManager method getConnection.

/**
     * Obtains a connection.
     * This method does not block.
     *
     * @param route     where the connection should point to
     *
     * @return  a connection that can be used to communicate
     *          along the given route
     */
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
    if (route == null) {
        throw new IllegalArgumentException("Route may not be null.");
    }
    assertStillUp();
    if (log.isDebugEnabled()) {
        log.debug("Get connection for route " + route);
    }
    if (managedConn != null)
        revokeConnection();
    // check re-usability of the connection
    boolean recreate = false;
    boolean shutdown = false;
    // Kill the connection if it expired.
    closeExpiredConnections();
    if (uniquePoolEntry.connection.isOpen()) {
        RouteTracker tracker = uniquePoolEntry.tracker;
        shutdown = (// can happen if method is aborted
        tracker == null || !tracker.toRoute().equals(route));
    } else {
        // If the connection is not open, create a new PoolEntry,
        // as the connection may have been marked not reusable,
        // due to aborts -- and the PoolEntry should not be reused
        // either.  There's no harm in recreating an entry if
        // the connection is closed.
        recreate = true;
    }
    if (shutdown) {
        recreate = true;
        try {
            uniquePoolEntry.shutdown();
        } catch (IOException iox) {
            log.debug("Problem shutting down connection.", iox);
        }
    }
    if (recreate)
        uniquePoolEntry = new PoolEntry();
    // updated statistics options.
    try {
        final Socket socket = uniquePoolEntry.connection.getSocket();
        if (socket != null) {
            SocketTagger.get().tag(socket);
        }
    } catch (IOException iox) {
        log.debug("Problem tagging socket.", iox);
    }
    // END android-changed
    managedConn = new ConnAdapter(uniquePoolEntry, route);
    return managedConn;
}
Also used : IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker) Socket(java.net.Socket)

Example 4 with RouteTracker

use of org.apache.http.conn.routing.RouteTracker in project XobotOS by xamarin.

the class AbstractPoolEntry method open.

/**
     * Opens the underlying connection.
     *
     * @param route         the route along which to open the connection
     * @param context       the context for opening the connection
     * @param params        the parameters for opening the connection
     *
     * @throws IOException  in case of a problem
     */
public void open(HttpRoute route, HttpContext context, HttpParams params) throws IOException {
    if (route == null) {
        throw new IllegalArgumentException("Route must not be null.");
    }
    //@@@ is context allowed to be null? depends on operator?
    if (params == null) {
        throw new IllegalArgumentException("Parameters must not be null.");
    }
    if ((this.tracker != null) && this.tracker.isConnected()) {
        throw new IllegalStateException("Connection already open.");
    }
    // - collect the arguments
    // - call the operator
    // - update the tracking data
    // In this order, we can be sure that only a successful
    // opening of the connection will be tracked.
    //@@@ verify route against planned route?
    this.tracker = new RouteTracker(route);
    final HttpHost proxy = route.getProxyHost();
    connOperator.openConnection(this.connection, (proxy != null) ? proxy : route.getTargetHost(), route.getLocalAddress(), context, params);
    // capture volatile        
    RouteTracker localTracker = tracker;
    // fail early.
    if (localTracker == null) {
        throw new IOException("Request aborted");
    }
    if (proxy == null) {
        localTracker.connectTarget(this.connection.isSecure());
    } else {
        localTracker.connectProxy(proxy, this.connection.isSecure());
    }
}
Also used : HttpHost(org.apache.http.HttpHost) IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker)

Example 5 with RouteTracker

use of org.apache.http.conn.routing.RouteTracker in project platform_external_apache-http by android.

the class SingleClientConnManager method getConnection.

/**
     * Obtains a connection.
     * This method does not block.
     *
     * @param route     where the connection should point to
     *
     * @return  a connection that can be used to communicate
     *          along the given route
     */
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
    if (route == null) {
        throw new IllegalArgumentException("Route may not be null.");
    }
    assertStillUp();
    if (log.isDebugEnabled()) {
        log.debug("Get connection for route " + route);
    }
    if (managedConn != null)
        revokeConnection();
    // check re-usability of the connection
    boolean recreate = false;
    boolean shutdown = false;
    // Kill the connection if it expired.
    closeExpiredConnections();
    if (uniquePoolEntry.connection.isOpen()) {
        RouteTracker tracker = uniquePoolEntry.tracker;
        shutdown = (// can happen if method is aborted
        tracker == null || !tracker.toRoute().equals(route));
    } else {
        // If the connection is not open, create a new PoolEntry,
        // as the connection may have been marked not reusable,
        // due to aborts -- and the PoolEntry should not be reused
        // either.  There's no harm in recreating an entry if
        // the connection is closed.
        recreate = true;
    }
    if (shutdown) {
        recreate = true;
        try {
            uniquePoolEntry.shutdown();
        } catch (IOException iox) {
            log.debug("Problem shutting down connection.", iox);
        }
    }
    if (recreate)
        uniquePoolEntry = new PoolEntry();
    // updated statistics options.
    try {
        final Socket socket = uniquePoolEntry.connection.getSocket();
        if (socket != null) {
            TrafficStats.tagSocket(socket);
        }
    } catch (IOException iox) {
        log.debug("Problem tagging socket.", iox);
    }
    // END android-changed
    managedConn = new ConnAdapter(uniquePoolEntry, route);
    return managedConn;
}
Also used : IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker) Socket(java.net.Socket)

Aggregations

RouteTracker (org.apache.http.conn.routing.RouteTracker)10 IOException (java.io.IOException)6 HttpHost (org.apache.http.HttpHost)6 InterruptedIOException (java.io.InterruptedIOException)4 OperatedClientConnection (org.apache.http.conn.OperatedClientConnection)4 ConnectionShutdownException (org.apache.http.impl.conn.ConnectionShutdownException)4 Socket (java.net.Socket)3