protected void evaluateQoSActions(){
  if (log.isTraceEnabled()) {
    Set<ObjectInstance> instances=mbeanServer.queryMBeans(null,null);
    for (    ObjectInstance instance : instances) {
      log.trace("MBean Found:");
      log.trace("Class Name:t" + instance.getClassName());
      log.trace("Object Name:t" + instance.getObjectName());
      log.trace("****************************************");
    }
  }
  int validSentinels=0;
  List<Double> currentSentinelRatios=new ArrayList<>();
  for (  QoSSentinel sentinel : qosSentinels) {
    String name="metrics:name=" + prefix + "routing."+ sentinel.getName()+ ".duration";
    try {
      ObjectName beanName=new ObjectName(name);
      if (mbeanServer.isRegistered(beanName)) {
        int currentSampleCount=(Integer)mbeanServer.getAttribute(beanName,"Count");
        if (currentSampleCount >= globalQoSConfig.getMinSampleCount()) {
          double currentResponseTime=0.0;
          if (sentinel.getPercentile() != null) {
            currentResponseTime=(Double)mbeanServer.getAttribute(beanName,"" + sentinel.getPercentile() + PERCENTILE_SUFFIX);
          }
 else {
            currentResponseTime=(Double)mbeanServer.getAttribute(beanName,"" + globalQoSConfig.getPercentile() + PERCENTILE_SUFFIX);
          }
          if (sentinel.getLowestPercentileValue() > currentResponseTime) {
            sentinel.setLowestPercentileValue(currentResponseTime);
          }
          currentSentinelRatios.add(currentResponseTime / sentinel.getLowestPercentileValue());
          validSentinels++;
        }
 else {
          log.warn("Sentinel " + sentinel.getName() + " doesn't have enough samples yet ("+ currentSampleCount+ "/"+ globalQoSConfig.getMinSampleCount()+ ")");
        }
      }
 else {
        log.warn("MBean {} for sentinel {} is not ready yet ...",name,sentinel.getName());
      }
    }
 catch (    MalformedObjectNameException e) {
      log.error("Could not load MBean for metric name '" + sentinel.getName() + "'.",e);
    }
catch (    AttributeNotFoundException e) {
    }
catch (    InstanceNotFoundException e) {
      log.error("Could not find attribute " + sentinel.getPercentile() + PERCENTILE_SUFFIX+ " for the MBean of the metric '"+ sentinel.getName()+ "'.",e);
    }
catch (    MBeanException|ReflectionException e) {
      log.error("Could not load value of attribute " + sentinel.getPercentile() + PERCENTILE_SUFFIX+ " for the MBean of the metric '"+ sentinel.getName()+ "'.",e);
    }
  }
  if (validSentinels >= globalQoSConfig.getMinSentinelCount()) {
    int threshold=(int)Math.ceil(validSentinels / 100.0 * globalQoSConfig.getQuorum()) - 1;
    Collections.sort(currentSentinelRatios,Collections.reverseOrder());
    if (log.isTraceEnabled()) {
      for (      double sentinelRatio : currentSentinelRatios) {
        log.trace(" -> {}",sentinelRatio);
      }
    }
    log.debug("Successfully read sentinels: {}",validSentinels);
    log.debug("Threshold index: {}",threshold);
    log.debug("Threshold ratio: {}",currentSentinelRatios.get(threshold));
    for (    QoSRule rule : qosRules) {
      Double warn=rule.getWarn();
      Double reject=rule.getReject();
      if (actionNecessary(reject,currentSentinelRatios.get(threshold))) {
        log.debug("rule will be rejected: {}",rule.getUrlPattern());
        rule.addAction(REJECT_ACTION);
      }
 else {
        log.debug("rule will not be rejected: {}",rule.getUrlPattern());
        rule.removeAction(REJECT_ACTION);
      }
      if (actionNecessary(warn,currentSentinelRatios.get(threshold))) {
        log.debug("rule will be logged with a warning: {}",rule.getUrlPattern());
        rule.addAction(WARN_ACTION);
      }
 else {
        log.debug("rule will not be logged with a warning: {}",rule.getUrlPattern());
        rule.removeAction(WARN_ACTION);
      }
    }
  }
 else {
    qosRules.forEach(null);
  }
}

protected void evaluateQoSActions ( ) { if ( log . isTraceEnabled ( ) ) { Set < ObjectInstance > instances = mbeanServer . queryMBeans ( null , null ) ; for ( ObjectInstance instance : instances ) { log . trace ( "MBean Found:" ) ; log . trace ( "Class Name:t" + instance . getClassName ( ) ) ; log . trace ( "Object Name:t" + instance . getObjectName ( ) ) ; log . trace ( "****************************************" ) ; } } int validSentinels = 0 ; List < Double > currentSentinelRatios = new ArrayList < > ( ) ; for ( QoSSentinel sentinel : qosSentinels ) { String name = "metrics:name=" + prefix + "routing." + sentinel . getName ( ) + ".duration" ; try { ObjectName beanName = new ObjectName ( name ) ; if ( mbeanServer . isRegistered ( beanName ) ) { int currentSampleCount = ( Integer ) mbeanServer . getAttribute ( beanName , "Count" ) ; if ( currentSampleCount >= globalQoSConfig . getMinSampleCount ( ) ) { double currentResponseTime = 0.0 ; if ( sentinel . getPercentile ( ) != null ) { currentResponseTime = ( Double ) mbeanServer . getAttribute ( beanName , "" + sentinel . getPercentile ( ) + PERCENTILE_SUFFIX ) ; } else { currentResponseTime = ( Double ) mbeanServer . getAttribute ( beanName , "" + globalQoSConfig . getPercentile ( ) + PERCENTILE_SUFFIX ) ; } if ( sentinel . getLowestPercentileValue ( ) > currentResponseTime ) { sentinel . setLowestPercentileValue ( currentResponseTime ) ; } currentSentinelRatios . add ( currentResponseTime / sentinel . getLowestPercentileValue ( ) ) ; validSentinels ++ ; } else { log . warn ( "Sentinel " + sentinel . getName ( ) + " doesn't have enough samples yet (" + currentSampleCount + "/" + globalQoSConfig . getMinSampleCount ( ) + ")" ) ; } } else { log . warn ( "MBean {} for sentinel {} is not ready yet ..." , name , sentinel . getName ( ) ) ; } } catch ( MalformedObjectNameException e ) { log . error ( "Could not load MBean for metric name '" + sentinel . getName ( ) + "'." , e ) ; } catch ( AttributeNotFoundException e ) { } catch ( InstanceNotFoundException e ) { log . error ( "Could not find attribute " + sentinel . getPercentile ( ) + PERCENTILE_SUFFIX + " for the MBean of the metric '" + sentinel . getName ( ) + "'." , e ) ; } catch ( MBeanException | ReflectionException e ) { log . error ( "Could not load value of attribute " + sentinel . getPercentile ( ) + PERCENTILE_SUFFIX + " for the MBean of the metric '" + sentinel . getName ( ) + "'." , e ) ; } } if ( validSentinels >= globalQoSConfig . getMinSentinelCount ( ) ) { int threshold = ( int ) Math . ceil ( validSentinels / 100.0 * globalQoSConfig . getQuorum ( ) ) - 1 ; Collections . sort ( currentSentinelRatios , Collections . reverseOrder ( ) ) ; if ( log . isTraceEnabled ( ) ) { for ( double sentinelRatio : currentSentinelRatios ) { log . trace ( " -> {}" , sentinelRatio ) ; } } log . debug ( "Successfully read sentinels: {}" , validSentinels ) ; log . debug ( "Threshold index: {}" , threshold ) ; log . debug ( "Threshold ratio: {}" , currentSentinelRatios . get ( threshold ) ) ; for ( QoSRule rule : qosRules ) { Double warn = rule . getWarn ( ) ; Double reject = rule . getReject ( ) ; if ( actionNecessary ( reject , currentSentinelRatios . get ( threshold ) ) ) { log . debug ( "rule will be rejected: {}" , rule . getUrlPattern ( ) ) ; rule . addAction ( REJECT_ACTION ) ; } else { log . debug ( "rule will not be rejected: {}" , rule . getUrlPattern ( ) ) ; rule . removeAction ( REJECT_ACTION ) ; } if ( actionNecessary ( warn , currentSentinelRatios . get ( threshold ) ) ) { log . debug ( "rule will be logged with a warning: {}" , rule . getUrlPattern ( ) ) ; rule . addAction ( WARN_ACTION ) ; } else { log . debug ( "rule will not be logged with a warning: {}" , rule . getUrlPattern ( ) ) ; rule . removeAction ( WARN_ACTION ) ; } } } else { qosRules . forEach ( null ) ; } }
calculates the threshold and determines if any action for each rule has to be applied .
