001
014
015 package com.liferay.portal.kernel.monitoring.statistics;
016
017
021 public class AverageStatistics extends BaseStatistics {
022
023 public AverageStatistics(String name) {
024 super(name);
025
026 _countStatistics = new CountStatistics(name);
027 }
028
029 public void addDuration(long duration) {
030 _countStatistics.incrementCount();
031
032 setLastTime(duration);
033
034 if (getMaxTime() < duration) {
035 setMaxTime(duration);
036 }
037 else if ((getMinTime() == 0) || (getMinTime() > duration)) {
038 setMinTime(duration);
039 }
040
041 if (_averageTime == 0) {
042 _averageTime = duration;
043 }
044 else {
045 long span = 0;
046
047 if (_countStatistics.getCount() < getLowerBound()) {
048 span = getLowerBound();
049 }
050 else if (_countStatistics.getCount() > getUpperBound()) {
051 span = getUpperBound();
052 }
053 else {
054 span = _countStatistics.getCount();
055 }
056
057 _averageTime = (_averageTime * span + duration) / (span + 1);
058 }
059
060 setLastSampleTime(System.currentTimeMillis());
061 }
062
063 public long getAverageTime() {
064 return _averageTime;
065 }
066
067 public long getCount() {
068 return _countStatistics.getCount();
069 }
070
071 @Override
072 public void reset() {
073 super.reset();
074
075 _averageTime = 0;
076 }
077
078 private long _averageTime;
079 private CountStatistics _countStatistics;
080
081 }