com.squareup.okhttp.Route Java Examples

The following examples show how to use com.squareup.okhttp.Route. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteSelector.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next() throws IOException {
  // Always prefer pooled connections over new connections.
  Connection pooled = pool.get(address);
  if (pooled != null) {
    return pooled;
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (failedRoutes.contains(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next();
  }

  return new Connection(route);
}
 
Example #2
Source File: RouteSelector.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, RouteDatabase routeDatabase) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.routeDatabase = routeDatabase;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #3
Source File: RouteSelector.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #4
Source File: RouteSelector.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #5
Source File: RouteSelector.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, RouteDatabase routeDatabase) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.routeDatabase = routeDatabase;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #6
Source File: RouteSelector.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #7
Source File: RouteSelector.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #8
Source File: RouteSelector.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, RouteDatabase routeDatabase) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.routeDatabase = routeDatabase;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #9
Source File: RouteSelector.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #10
Source File: RouteSelector.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #11
Source File: HttpURLConnectionImpl.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
public HttpURLConnectionImpl(URL url, OkHttpClient client, OkResponseCache responseCache,
    Set<Route> failedRoutes) {
  super(url);
  this.followProtocolRedirects = client.getFollowProtocolRedirects();
  this.failedRoutes = failedRoutes;
  this.requestedProxy = client.getProxy();
  this.proxySelector = client.getProxySelector();
  this.cookieHandler = client.getCookieHandler();
  this.connectionPool = client.getConnectionPool();
  this.sslSocketFactory = client.getSslSocketFactory();
  this.hostnameVerifier = client.getHostnameVerifier();
  this.responseCache = responseCache;
}
 
Example #12
Source File: RouteSelector.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, Set<Route> failedRoutes) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.failedRoutes = failedRoutes;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #13
Source File: RouteSelector.java    From L.TileLayer.Cordova with MIT License 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #14
Source File: RouteSelector.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  failedRoutes.add(failedRoute);
  if (!(failure instanceof SSLHandshakeException)) {
    // If the problem was not related to SSL then it will also fail with
    // a different Tls mode therefore we can be proactive about it.
    failedRoutes.add(failedRoute.flipTlsMode());
  }
}
 
Example #15
Source File: RouteSelector.java    From wildfly-samples with MIT License 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, RouteDatabase routeDatabase) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.routeDatabase = routeDatabase;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #16
Source File: RouteSelector.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #17
Source File: RouteSelector.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #18
Source File: HttpURLConnectionImpl.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
public HttpURLConnectionImpl(URL url, OkHttpClient client, OkResponseCache responseCache,
    Set<Route> failedRoutes) {
  super(url);
  this.followProtocolRedirects = client.getFollowProtocolRedirects();
  this.failedRoutes = failedRoutes;
  this.requestedProxy = client.getProxy();
  this.proxySelector = client.getProxySelector();
  this.cookieHandler = client.getCookieHandler();
  this.connectionPool = client.getConnectionPool();
  this.sslSocketFactory = client.getSslSocketFactory();
  this.hostnameVerifier = client.getHostnameVerifier();
  this.responseCache = responseCache;
}
 
Example #19
Source File: RouteSelector.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, Set<Route> failedRoutes) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.failedRoutes = failedRoutes;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #20
Source File: RouteSelector.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next() throws IOException {
  // Always prefer pooled connections over new connections.
  Connection pooled = pool.get(address);
  if (pooled != null) {
    return pooled;
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (failedRoutes.contains(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next();
  }

  return new Connection(route);
}
 
Example #21
Source File: RouteSelector.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  failedRoutes.add(failedRoute);
  if (!(failure instanceof SSLHandshakeException)) {
    // If the problem was not related to SSL then it will also fail with
    // a different Tls mode therefore we can be proactive about it.
    failedRoutes.add(failedRoute.flipTlsMode());
  }
}
 
Example #22
Source File: RouteSelector.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool,
    Dns dns, RouteDatabase routeDatabase) {
  this.address = address;
  this.uri = uri;
  this.proxySelector = proxySelector;
  this.pool = pool;
  this.dns = dns;
  this.routeDatabase = routeDatabase;
  this.postponedRoutes = new LinkedList<Route>();

  resetNextProxy(uri, address.getProxy());
}
 
Example #23
Source File: RouteSelector.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}
 
Example #24
Source File: RouteSelector.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #25
Source File: RouteSelector.java    From reader with MIT License 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #26
Source File: RouteSelector.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public RouteSelector(Address address, URI uri, ProxySelector proxySelector, ConnectionPool pool, Dns dns, RouteDatabase routeDatabase) {
    this.address = address;
    this.uri = uri;
    this.proxySelector = proxySelector;
    this.pool = pool;
    this.dns = dns;
    this.routeDatabase = routeDatabase;
    this.postponedRoutes = new LinkedList<Route>();

    resetNextProxy(uri, address.getProxy());
}
 
Example #27
Source File: RouteSelector.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
    // Always prefer pooled connections over new connections.
    for (Connection pooled; (pooled = pool.get(address)) != null; ) {
        if (method.equals("GET") || pooled.isReadable())
            return pooled;
        pooled.close();
    }

    // Compute the next route to attempt.
    if (!hasNextTlsMode()) {
        if (!hasNextInetSocketAddress()) {
            if (!hasNextProxy()) {
                if (!hasNextPostponed()) {
                    throw new NoSuchElementException();
                }
                return new Connection(nextPostponed());
            }
            lastProxy = nextProxy();
            resetNextInetSocketAddress(lastProxy);
        }
        lastInetSocketAddress = nextInetSocketAddress();
        resetNextTlsMode();
    }

    boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
    Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
    if (routeDatabase.shouldPostpone(route)) {
        postponedRoutes.add(route);
        // We will only recurse in order to skip previously failed routes. They will be
        // tried last.
        return next(method);
    }

    return new Connection(route);
}
 
Example #28
Source File: RouteSelector.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
    Route failedRoute = connection.getRoute();
    if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
        // Tell the proxy selector when we fail to connect on a fresh connection.
        proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
    }

    routeDatabase.failed(failedRoute, failure);
}
 
Example #29
Source File: RouteSelector.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/**
 * Clients should invoke this method when they encounter a connectivity
 * failure on a connection returned by this route selector.
 */
public void connectFailed(Connection connection, IOException failure) {
  Route failedRoute = connection.getRoute();
  if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
    // Tell the proxy selector when we fail to connect on a fresh connection.
    proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
  }

  routeDatabase.failed(failedRoute, failure);
}
 
Example #30
Source File: RouteSelector.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/**
 * Returns the next route address to attempt.
 *
 * @throws NoSuchElementException if there are no more routes to attempt.
 */
public Connection next(String method) throws IOException {
  // Always prefer pooled connections over new connections.
  for (Connection pooled; (pooled = pool.get(address)) != null; ) {
    if (method.equals("GET") || pooled.isReadable()) return pooled;
    pooled.close();
  }

  // Compute the next route to attempt.
  if (!hasNextTlsMode()) {
    if (!hasNextInetSocketAddress()) {
      if (!hasNextProxy()) {
        if (!hasNextPostponed()) {
          throw new NoSuchElementException();
        }
        return new Connection(nextPostponed());
      }
      lastProxy = nextProxy();
      resetNextInetSocketAddress(lastProxy);
    }
    lastInetSocketAddress = nextInetSocketAddress();
    resetNextTlsMode();
  }

  boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
  Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
  if (routeDatabase.shouldPostpone(route)) {
    postponedRoutes.add(route);
    // We will only recurse in order to skip previously failed routes. They will be
    // tried last.
    return next(method);
  }

  return new Connection(route);
}