test_class.file: core/src/test/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderTest.java
test_class.identifier: DynamicLoadBalanceFactorProviderTest
test_case.body: @Test
      public void getLoadBalanceFactor() throws Exception {
          Engine engine = mock(Engine.class);
  
          Set<LoadMetric> metrics = new HashSet<>();
          LoadMetric metric = mock(LoadMetric.class);
          when(metric.getWeight()).thenReturn(LoadMetric.DEFAULT_WEIGHT);
          when(metric.getLoad(engine)).thenThrow(new NodeUnavailableException());
          metrics.add(metric);
  
          DynamicLoadBalanceFactorProvider provider = new DynamicLoadBalanceFactorProvider(metrics);
  
          int loadBalanceFactor = provider.getLoadBalanceFactor(engine);
          assertEquals(-1, loadBalanceFactor);
      }
test_case.class_method_signature: DynamicLoadBalanceFactorProviderTest.getLoadBalanceFactor()
test_case.full_signature: @Test public void getLoadBalanceFactor()
test_case.identifier: getLoadBalanceFactor
test_case.invocations: mock mock thenReturn when getWeight thenThrow when getLoad add getLoadBalanceFactor assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void getLoadBalanceFactor()
focal_class.declarator: DEFAULT_INITIAL_LOAD = 0
focal_class.modifier: public static final
focal_class.original_string: public static final int DEFAULT_INITIAL_LOAD = 0;
focal_class.type: int
focal_class.var_name: DEFAULT_INITIAL_LOAD
focal_class.declarator: DEFAULT_DECAY_FACTOR = 2
focal_class.modifier: public static final
focal_class.original_string: public static final float DEFAULT_DECAY_FACTOR = 2;
focal_class.type: float
focal_class.var_name: DEFAULT_DECAY_FACTOR
focal_class.declarator: DEFAULT_HISTORY = 9
focal_class.modifier: public static final
focal_class.original_string: public static final int DEFAULT_HISTORY = 9;
focal_class.type: int
focal_class.var_name: DEFAULT_HISTORY
focal_class.declarator: log = Logger.getLogger(this.getClass())
focal_class.modifier: private final
focal_class.original_string: private final Logger log = Logger.getLogger(this.getClass());
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: loadHistory = new LinkedHashMap<LoadMetric, List<Double>>()
focal_class.modifier: private final
focal_class.original_string: private final Map<LoadMetric, List<Double>> loadHistory = new LinkedHashMap<LoadMetric, List<Double>>();
focal_class.type: Map<LoadMetric, List<Double>>
focal_class.var_name: loadHistory
focal_class.declarator: decayFactor = DEFAULT_DECAY_FACTOR
focal_class.modifier: private volatile
focal_class.original_string: private volatile float decayFactor = DEFAULT_DECAY_FACTOR;
focal_class.type: float
focal_class.var_name: decayFactor
focal_class.declarator: history = DEFAULT_HISTORY
focal_class.modifier: private volatile
focal_class.original_string: private volatile int history = DEFAULT_HISTORY;
focal_class.type: int
focal_class.var_name: history
focal_class.file: core/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
focal_class.identifier: DynamicLoadBalanceFactorProvider
focal_class.interfaces: implements LoadBalanceFactorProvider, DynamicLoadBalanceFactorProviderMBean
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics)
focal_class.full_signature: public  DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics)
focal_class.identifier: DynamicLoadBalanceFactorProvider
focal_class.modifiers: public
focal_class.parameters: (Set<LoadMetric> metrics)
focal_class.signature:  DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics, int initialLoad)
focal_class.full_signature: public  DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics, int initialLoad)
focal_class.identifier: DynamicLoadBalanceFactorProvider
focal_class.modifiers: public
focal_class.parameters: (Set<LoadMetric> metrics, int initialLoad)
focal_class.signature:  DynamicLoadBalanceFactorProvider(Set<LoadMetric> metrics, int initialLoad)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.getMetrics()
focal_class.full_signature: @Override public synchronized Map<String, Double> getMetrics()
focal_class.identifier: getMetrics
focal_class.modifiers: @Override public synchronized
focal_class.parameters: ()
focal_class.return: Map<String, Double>
focal_class.signature: Map<String, Double> getMetrics()
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.getLoadBalanceFactor(Engine engine)
focal_class.full_signature: @Override public synchronized int getLoadBalanceFactor(Engine engine)
focal_class.identifier: getLoadBalanceFactor
focal_class.modifiers: @Override public synchronized
focal_class.parameters: (Engine engine)
focal_class.return: int
focal_class.signature: int getLoadBalanceFactor(Engine engine)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.recordLoad(List<Double> queue, double load)
focal_class.full_signature: private void recordLoad(List<Double> queue, double load)
focal_class.identifier: recordLoad
focal_class.modifiers: private
focal_class.parameters: (List<Double> queue, double load)
focal_class.return: void
focal_class.signature: void recordLoad(List<Double> queue, double load)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.average(List<Double> queue)
focal_class.full_signature: private double average(List<Double> queue)
focal_class.identifier: average
focal_class.modifiers: private
focal_class.parameters: (List<Double> queue)
focal_class.return: double
focal_class.signature: double average(List<Double> queue)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.getDecayFactor()
focal_class.full_signature: @Override public float getDecayFactor()
focal_class.identifier: getDecayFactor
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: float
focal_class.signature: float getDecayFactor()
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.setDecayFactor(float decayFactor)
focal_class.full_signature: @Override public void setDecayFactor(float decayFactor)
focal_class.identifier: setDecayFactor
focal_class.modifiers: @Override public
focal_class.parameters: (float decayFactor)
focal_class.return: void
focal_class.signature: void setDecayFactor(float decayFactor)
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.getHistory()
focal_class.full_signature: @Override public int getHistory()
focal_class.identifier: getHistory
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getHistory()
focal_class.class_method_signature: DynamicLoadBalanceFactorProvider.setHistory(int history)
focal_class.full_signature: @Override public void setHistory(int history)
focal_class.identifier: setHistory
focal_class.modifiers: @Override public
focal_class.parameters: (int history)
focal_class.return: void
focal_class.signature: void setHistory(int history)
focal_method.body: @Override
      public synchronized int getLoadBalanceFactor(Engine engine) {
          boolean nodeUnavailable = false;
          int totalWeight = 0;
          double totalWeightedLoad = 0;
  
          for (Map.Entry<LoadMetric, List<Double>> entry : this.loadHistory.entrySet()) {
              LoadMetric metric = entry.getKey();
  
              int weight = metric.getWeight();
  
              if (weight > 0) {
                  List<Double> metricLoadHistory = entry.getValue();
  
                  try {
                      // Normalize load with respect to capacity
                      this.recordLoad(metricLoadHistory, metric.getLoad(engine) / metric.getCapacity());
  
                      totalWeight += weight;
                      totalWeightedLoad += this.average(metricLoadHistory) * weight;
                  } catch (NodeUnavailableException e) {
                      // The metric requested to put the node into error state
                      // Call LoadMetric#getLoad on remaining metrics so that historical values are populated
                      nodeUnavailable = true;
                  } catch (Exception e) {
                      this.log.error(e.getLocalizedMessage(), e);
                  }
              }
          }
  
          if (nodeUnavailable) {
              return -1;
          }
  
          // Convert load ratio to integer percentage
          int load = (int) Math.round(100 * totalWeightedLoad / totalWeight);
  
          // apply ceiling & floor and invert to express as "load factor"
          // result should be a value between 1-100
          return 100 - Math.max(0, Math.min(load, 99));
      }
focal_method.class_method_signature: DynamicLoadBalanceFactorProvider.getLoadBalanceFactor(Engine engine)
focal_method.full_signature: @Override public synchronized int getLoadBalanceFactor(Engine engine)
focal_method.identifier: getLoadBalanceFactor
focal_method.invocations: entrySet getKey getWeight getValue recordLoad getLoad getCapacity average error getLocalizedMessage round max min
focal_method.modifiers: @Override public synchronized
focal_method.parameters: (Engine engine)
focal_method.return: int
focal_method.signature: int getLoadBalanceFactor(Engine engine)