public Selection next() throws IOException { if (!hasNext()) { throw new NoSuchElementException(); } // Compute the next set of routes to attempt. List<Route> routes = new ArrayList<>(); while (hasNextProxy()) { // Postponed routes are always tried last. For example, if we have 2 proxies and all the // routes for proxy1 should be postponed, we'll move to proxy2. Only after we've exhausted // all the good routes will we attempt the postponed routes. Proxy proxy = nextProxy(); for (int i = 0, size = inetSocketAddresses.size(); i < size; i++) { Route route = new Route(address, proxy, inetSocketAddresses.get(i)); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); } else { routes.add(route); } } if (!routes.isEmpty()) { break; } } if (routes.isEmpty()) { // We've exhausted all Proxies so fallback to the postponed routes. routes.addAll(postponedRoutes); postponedRoutes.clear(); } return new Selection(routes); }
public Selection next() throws IOException { if (!hasNext()) { throw new NoSuchElementException(); } // Compute the next set of routes to attempt. List<Route> routes = new ArrayList<>(); while (hasNextProxy()) { // Postponed routes are always tried last. For example, if we have 2 proxies and all the // routes for proxy1 should be postponed, we'll move to proxy2. Only after we've exhausted // all the good routes will we attempt the postponed routes. Proxy proxy = nextProxy(); for (int i = 0, size = inetSocketAddresses.size(); i < size; i++) { Route route = new Route(address, proxy, inetSocketAddresses.get(i)); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); } else { routes.add(route); } } if (!routes.isEmpty()) { break; } } if (routes.isEmpty()) { // We've exhausted all Proxies so fallback to the postponed routes. routes.addAll(postponedRoutes); postponedRoutes.clear(); } return new Selection(routes); }
public Selection next() throws IOException { if (!hasNext()) { throw new NoSuchElementException(); } // Compute the next set of routes to attempt. List<Route> routes = new ArrayList<>(); while (hasNextProxy()) { // Postponed routes are always tried last. For example, if we have 2 proxies and all the // routes for proxy1 should be postponed, we'll move to proxy2. Only after we've exhausted // all the good routes will we attempt the postponed routes. Proxy proxy = nextProxy(); for (int i = 0, size = inetSocketAddresses.size(); i < size; i++) { Route route = new Route(address, proxy, inetSocketAddresses.get(i)); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); } else { routes.add(route); } } if (!routes.isEmpty()) { break; } } if (routes.isEmpty()) { // We've exhausted all Proxies so fallback to the postponed routes. routes.addAll(postponedRoutes); postponedRoutes.clear(); } return new Selection(routes); }
public Selection next() throws IOException { if (!hasNext()) { throw new NoSuchElementException(); } // Compute the next set of routes to attempt. List<Route> routes = new ArrayList<>(); while (hasNextProxy()) { // Postponed routes are always tried last. For example, if we have 2 proxies and all the // routes for proxy1 should be postponed, we'll move to proxy2. Only after we've exhausted // all the good routes will we attempt the postponed routes. Proxy proxy = nextProxy(); for (int i = 0, size = inetSocketAddresses.size(); i < size; i++) { Route route = new Route(address, proxy, inetSocketAddresses.get(i)); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); } else { routes.add(route); } } if (!routes.isEmpty()) { break; } } if (routes.isEmpty()) { // We've exhausted all Proxies so fallback to the postponed routes. routes.addAll(postponedRoutes); postponedRoutes.clear(); } return new Selection(routes); }
public Route next() throws IOException { // Compute the next route to attempt. if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { throw new NoSuchElementException(); } return nextPostponed(); } lastProxy = nextProxy(); } lastInetSocketAddress = nextInetSocketAddress(); Route route = new Route(address, lastProxy, lastInetSocketAddress); 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(); } return route; }
public Route next() throws IOException { // Compute the next route to attempt. if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { throw new NoSuchElementException(); } return nextPostponed(); } lastProxy = nextProxy(); } lastInetSocketAddress = nextInetSocketAddress(); Route route = new Route(address, lastProxy, lastInetSocketAddress); 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(); } return route; }
public Route next() throws IOException { // Compute the next route to attempt. if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { throw new NoSuchElementException(); } return nextPostponed(); } lastProxy = nextProxy(); } lastInetSocketAddress = nextInetSocketAddress(); Route route = new Route(address, lastProxy, lastInetSocketAddress); 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(); } return route; }
@Before public void beforeMethod() { MockitoAnnotations.initMocks(this); // setup some dummy data so that we dont get NPEs Address address = new Address("localhost", 8080, mockDns, socketFactory, null, null, null, proxyAuthenticator, null, Collections.singletonList(Protocol.HTTP_1_1), Collections.singletonList(ConnectionSpec.MODERN_TLS), proxySelector); InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 8080); mockRoute = new Route(address, proxy, inetSocketAddress); given(mockConnection.route()).willReturn(mockRoute); }
@Before public void beforeMethod() { MockitoAnnotations.initMocks(this); // setup some dummy data so that we dont get NPEs Address address = new Address("localhost", 8080, mockDns, socketFactory, null, null, null, proxyAuthenticator, null, Collections.singletonList(Protocol.HTTP_1_1), Collections.singletonList(ConnectionSpec.MODERN_TLS), proxySelector); InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 8080); mockRoute = new Route(address, proxy, inetSocketAddress); given(mockConnection.route()).willReturn(mockRoute); }
@Before public void beforeMethod() { Connection mockConnection = mock(Connection.class); Dns mockDns = mock(Dns.class); SocketFactory socketFactory = mock(SocketFactory.class); Authenticator proxyAuthenticator = mock(Authenticator.class); ProxySelector proxySelector = mock(ProxySelector.class); Proxy proxy = mock(Proxy.class); // setup some dummy data so that we dont get NPEs Address address = new Address("localhost", 8080, mockDns, socketFactory, null, null, null, proxyAuthenticator, null, Collections.singletonList(Protocol.HTTP_1_1), Collections.singletonList(ConnectionSpec.MODERN_TLS), proxySelector); InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 8080); mockRoute = new Route(address, proxy, inetSocketAddress); given(mockConnection.route()).willReturn(mockRoute); authenticator = new DigestAuthenticator(new Credentials("user1", "user1")); }