21 package com.griddynamics.jagger.invoker;
23 import com.griddynamics.jagger.util.Pair;
25 import com.google.common.collect.AbstractIterator;
27 import java.util.Iterator;
28 import java.util.Random;
29 import java.util.concurrent.atomic.AtomicLong;
41 public class RandomLoadBalancer<Q, E>
extends PairSupplierFactoryLoadBalancer<Q, E> {
43 private final AtomicLong randomSeed;
46 super(pairSupplierFactory);
47 this.randomSeed =
new AtomicLong(randomSeed);
51 return randomSeed.get();
62 return new AbstractIterator<Pair<Q,E>>() {
64 private PairSupplier<Q, E> pairs = getPairSupplier();
65 private int size = pairs.size();
66 private Random random =
new Random(randomSeed.getAndIncrement());
69 protected Pair<Q, E> computeNext() {
70 return pairs.get(random.nextInt(size));
74 public String toString() {
75 return "RandomLoadBalancer iterator";