public <T> LoadBalancerBuilder setCache( long checkInterval, TimeUnit checkTimeUnit, Class<T> returnType, BiFunction<Integer, CompletableFutureCache, CompletableFuture<T>> function) { loadBalancer.monitorCheckInterval = checkInterval; loadBalancer.monitorCheckTimeUnit = checkTimeUnit; // loadBalancer.monitorFunction = function; return this; }
public LoadBalancerBuilder setMonitor( long checkInterval, TimeUnit checkTimeUnit, int unhealthyThreshold, int healthyThreshold, Function<Integer, CompletableFuture<Boolean>> function) { loadBalancer.monitorCheckInterval = checkInterval; loadBalancer.monitorCheckTimeUnit = checkTimeUnit; loadBalancer.monitorUnhealthyThreshold = unhealthyThreshold; loadBalancer.monitorHealthyThreshold = healthyThreshold; loadBalancer.monitorFunction = function; return this; }
public LoadBalancerBuilder setMaxFailureRate( int maxFailures, long failuresTime, TimeUnit failuresTimeUnit, long suspensionTime, TimeUnit suspensionTimeUnit) { loadBalancer.failureRateMaxFailures = maxFailures; loadBalancer.failureRateTime = failuresTime; loadBalancer.failureRateTimeUnit = failuresTimeUnit; loadBalancer.suspensionTime = suspensionTime; loadBalancer.suspensionTimeUnit = suspensionTimeUnit; return this; }
public LoadBalancer build() { loadBalancer.suspensionTimes = new AtomicLongArray(loadBalancer.endpointCount); loadBalancer.successCounters = new AtomicLongArray(loadBalancer.endpointCount); loadBalancer.failureCounters = new AtomicLongArray(loadBalancer.endpointCount); loadBalancer.failureTimes = new AtomicLongArray[loadBalancer.endpointCount]; for (int i = 0; i < loadBalancer.failureTimes.length; i++) { loadBalancer.failureTimes[i] = new AtomicLongArray(loadBalancer.failureRateMaxFailures); } // Setup monitor if it has been set if (loadBalancer.monitorFunction != null) { loadBalancer.monitorUnhealthyCounters = new AtomicIntegerArray(loadBalancer.endpointCount); loadBalancer.monitorHealthyCounters = new AtomicIntegerArray(loadBalancer.endpointCount); loadBalancer.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); loadBalancer.scheduledExecutorService.scheduleWithFixedDelay( () -> { loadBalancer.checkMonitors(); }, 0, loadBalancer.monitorCheckInterval, loadBalancer.monitorCheckTimeUnit); } return loadBalancer; }
public LoadBalancerBuilder setPolicy(LoadBalancerPolicy policy) { loadBalancer.policy = policy; return this; }
public LoadBalancerBuilder setEndpointCount(int count) { loadBalancer.endpointCount = count; return this; }
public LoadBalancerBuilder setRetryCount(int retries) { loadBalancer.retries = retries; return this; }