1 21 package org.objectweb.fractal.jmx.julia.stat; 22 23 import org.objectweb.fractal.julia.loader.Tree; 24 import org.objectweb.fractal.julia.loader.Initializable; 25 26 38 public class BasicStatController implements StatController, Initializable { 39 40 44 protected long _period = 5000; 45 46 49 private int _calls; 50 51 54 private int _callsCrtSample; 55 56 59 private double _rateOfMethodCall; 60 61 67 private int _success; 68 69 72 private int _successCrtSample; 73 74 77 private double _rateOfMethodSuccess; 78 79 82 private long _startSample = System.currentTimeMillis(); 83 84 96 public void initialize(final Tree args) { 97 if (args.getSize() == 0) 99 return; 100 _period = Long.valueOf(args.getSubTree(0).toString()).longValue(); 101 if (_period < 1) 102 throw new IllegalStateException ("period=" + _period + " is invalid. The value must be positive."); 103 } 105 106 public synchronized void reset() { 110 _calls = 0; 111 _callsCrtSample = 0; 112 _rateOfMethodCall = 0; 113 _success = 0; 114 _successCrtSample = 0; 115 _rateOfMethodSuccess = 0; 116 _startSample = System.currentTimeMillis(); 117 } 118 119 public int getNumberOfMethodCall() { 120 return _calls; 121 } 122 123 public int getNumberOfMethodSuccess() { 124 return _success; 125 } 126 127 public double getRateOfMethodCall() { 128 resetSample(); 129 return _rateOfMethodCall; 130 } 131 132 public double getRateOfMethodSuccess() { 133 resetSample(); 134 return _rateOfMethodSuccess; 135 } 136 137 private synchronized void resetSample() { 138 long t = System.currentTimeMillis(); 139 if (t < _startSample + _period) 140 return; 141 _rateOfMethodCall = (double)(_callsCrtSample * 1000) / (t - _startSample); 142 _callsCrtSample = 0; 143 _rateOfMethodSuccess = (double)(_successCrtSample * 1000) / (t - _startSample); 144 _successCrtSample = 0; 145 _startSample = t; 146 } 147 148 158 public void statPreMethod(final String method) { 159 synchronized (this) { 160 ++_calls; 161 ++_callsCrtSample; 162 } 163 } 164 165 176 public void statPostMethod(final String method) { 177 synchronized (this) { 178 ++_success; 179 ++_successCrtSample; 180 } 181 } 182 } 183 184 | Popular Tags |