예제 #1
0
 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;
 }
예제 #2
0
 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;
 }
예제 #3
0
 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;
 }
예제 #4
0
    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;
    }
예제 #5
0
 public LoadBalancerBuilder setPolicy(LoadBalancerPolicy policy) {
   loadBalancer.policy = policy;
   return this;
 }
예제 #6
0
 public LoadBalancerBuilder setEndpointCount(int count) {
   loadBalancer.endpointCount = count;
   return this;
 }
예제 #7
0
 public LoadBalancerBuilder setRetryCount(int retries) {
   loadBalancer.retries = retries;
   return this;
 }