public Upstream next() {
        // if max attempts reached - do not call balancer
        if (attemptCount + 1 > maxRetryAttempts) {
            this.upstream = null;
            throw balancer.createUpstreamUnavailableException();
        }
        attemptCount++;
        if (upstreamCacheContext == null
                || (upstreamCacheContext.getPolicy() != CachePolicy.CACHE_PRIORITY && attemptCount > 1)
                || upstreamCacheContext.getOriginalUpstream() == null) {
            upstream = balancer.next(usedUpstreams);
            if (upstream == null) {
                throw balancer.createUpstreamUnavailableException();
            }
        } else {
            upstream = upstreamCacheContext.getOriginalUpstream();
        }
        return upstream;
    }
Retrieves next available upstream from load balancer; also increase usage count

@return next upstream from load balancer
@throws com.epam.aidial.core.storage.http.HttpException if max retry attempts are exceeded or next upstream is unavailable
server/src/main/java/com/epam/aidial/core/server/upstream/UpstreamRoute.java