@Override public Optional<HttpUrl> redirectToNextRoundRobin(HttpUrl current) { Optional<HttpUrl> nextUrl = getNext(currentUrl.get()); if (nextUrl.isPresent()) { return redirectTo(current, nextUrl.get()); } return redirectTo(current, baseUrls.get((currentUrl.get() + 1) % baseUrls.size())); }
@Override public Optional<HttpUrl> redirectToNextRoundRobin(HttpUrl current) { Optional<HttpUrl> nextUrl = getNext(currentUrl.get()); if (nextUrl.isPresent()) { return redirectTo(current, nextUrl.get()); } return redirectTo(current, baseUrls.get((currentUrl.get() + 1) % baseUrls.size())); }
@Override public Optional<HttpUrl> redirectToNext(HttpUrl existingUrl) { // if possible, determine the index of the passed in url (so we can be sure to return a url which is different) Optional<Integer> existingUrlIndex = indexFor(existingUrl); int potentialNextIndex = existingUrlIndex.orElse(currentUrl.get()); Optional<HttpUrl> nextUrl = getNext(potentialNextIndex); if (nextUrl.isPresent()) { return redirectTo(existingUrl, nextUrl.get()); } // No healthy URLs remain; re-balance across any specified nodes return redirectTo(existingUrl, baseUrls.get((existingUrlIndex.orElse(currentUrl.get()) + 1) % baseUrls.size())); }
@Override public Optional<HttpUrl> redirectToNext(HttpUrl existingUrl) { // if possible, determine the index of the passed in url (so we can be sure to return a url which is different) Optional<Integer> existingUrlIndex = indexFor(existingUrl); int potentialNextIndex = existingUrlIndex.orElse(currentUrl.get()); Optional<HttpUrl> nextUrl = getNext(potentialNextIndex); if (nextUrl.isPresent()) { return redirectTo(existingUrl, nextUrl.get()); } // No healthy URLs remain; re-balance across any specified nodes return redirectTo(existingUrl, baseUrls.get((existingUrlIndex.orElse(currentUrl.get()) + 1) % baseUrls.size())); }