1 package com.griddynamics.jagger.user.test.configurations.loadbalancer;
3 import com.griddynamics.jagger.invoker.CircularExclusiveAccessLoadBalancer;
4 import com.griddynamics.jagger.invoker.ExclusiveAccessLoadBalancer;
5 import com.griddynamics.jagger.invoker.NonCircularExclusiveAccessLoadBalancer;
6 import com.griddynamics.jagger.invoker.OneByOneLoadBalancer;
7 import com.griddynamics.jagger.invoker.OneByOnePairSupplierFactory;
8 import com.griddynamics.jagger.invoker.PairSupplierFactory;
9 import com.griddynamics.jagger.invoker.PairSupplierFactoryLoadBalancer;
10 import com.griddynamics.jagger.invoker.QueryPoolLoadBalancer;
11 import com.griddynamics.jagger.invoker.RandomLoadBalancer;
12 import com.griddynamics.jagger.invoker.RoundRobinLoadBalancer;
13 import com.griddynamics.jagger.invoker.RoundRobinPairSupplierFactory;
14 import com.griddynamics.jagger.invoker.SimpleCircularLoadBalancer;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import java.io.Serializable;
19 import java.util.Objects;
20 import java.util.Random;
29 private final static Logger log = LoggerFactory.getLogger(
JLoadBalancer.class);
37 return new Builder(loadBalancer);
53 private boolean exclusiveAccess;
54 private boolean oneIterationOnly;
62 this.loadBalancer = loadBalancer;
88 this.exclusiveAccess =
true;
99 this.oneIterationOnly =
true;
100 this.exclusiveAccess =
true;
108 public QueryPoolLoadBalancer
build() {
110 PairSupplierFactory pairSupplierFactory = null;
111 switch (loadBalancer) {
113 pairSupplierFactory =
new OneByOnePairSupplierFactory();
117 pairSupplierFactory =
new RoundRobinPairSupplierFactory();
121 PairSupplierFactoryLoadBalancer loadBalancer = null;
122 if (exclusiveAccess) {
123 if (oneIterationOnly) {
124 loadBalancer =
new NonCircularExclusiveAccessLoadBalancer(pairSupplierFactory);
126 loadBalancer =
new CircularExclusiveAccessLoadBalancer(pairSupplierFactory);
128 ((ExclusiveAccessLoadBalancer)loadBalancer).setRandomnessSeed(seed);
130 if (Objects.nonNull(seed)) {
131 loadBalancer =
new RandomLoadBalancer(seed, pairSupplierFactory);
133 loadBalancer =
new SimpleCircularLoadBalancer(pairSupplierFactory);
137 log.info(
"Built a {} load balancer", loadBalancer);