1 21 package org.objectweb.fractal.jmx.julia.stat; 22 23 import org.objectweb.fractal.julia.loader.Tree; 24 25 47 public class ExponentialSmoothingStatController extends BasicStatController { 48 52 protected double _alpha = 0.5; 53 54 private double _lastRateOfMethodCall; 55 56 private double _lastRateOfMethodSuccess; 57 58 74 public void initialize(final Tree args) { 75 if (args.getSize() == 0) 77 return; 78 else if (args.getSize() == 1){ 79 super.initialize(args); 80 return; 81 } 82 super.initialize(args); 83 _alpha = Double.valueOf(args.getSubTree(1).toString()).doubleValue(); 84 if ((_alpha < 0) || (_alpha > 1)) 85 throw new IllegalStateException ("alpha=" + _alpha + " is invalid. The value must in the interval [0-1]."); 86 } 88 89 public double getRateOfMethodCall() { 90 return _lastRateOfMethodCall = expSmoothing(super.getRateOfMethodCall(), _lastRateOfMethodCall); 91 } 92 93 public double getRateOfMethodSuccess() { 94 return _lastRateOfMethodSuccess = expSmoothing(super.getRateOfMethodSuccess(), _lastRateOfMethodSuccess); 95 } 96 97 public void reset() { 98 super.reset(); 99 _lastRateOfMethodCall = 0; 100 _lastRateOfMethodSuccess = 0; 101 } 102 103 private double expSmoothing(double newRate, double lastRate) { 104 return (_alpha * newRate) + (1 - _alpha) * lastRate; 105 } 106 } 107 108 | Popular Tags |