21 package com.griddynamics.jagger.invoker;
23 import com.griddynamics.jagger.util.Pair;
25 import java.util.Iterator;
40 public class OneByOneLoadBalancer<Q, E>
extends QueryPoolLoadBalancer<Q, E> {
47 super(queryProvider, endpointProvider);
59 final CircularSupplier<Q> querySupplier = CircularSupplier.create(queryProvider);
60 final CircularSupplier<E> endpointSupplier = CircularSupplier.create(endpointProvider);
62 return new Iterator<Pair<Q, E>>() {
64 public boolean hasNext() {
69 public Pair<Q, E> next() {
70 boolean exceeded = endpointSupplier.exceeded();
72 E endpoint = endpointSupplier.pop();
73 Q query = exceeded ? querySupplier.pop() : querySupplier.peek();
75 return Pair.of(query, endpoint);
80 public void remove() {
81 throw new UnsupportedOperationException(
"Read only iterator");
85 public String toString() {
86 return "OneByOneLoadBalancer iterator";
94 return "OneByOneLoadBalancer";