super.getValues(report, numericMetricSchedules);
}
private CallTimeData createCallTimeData(MeasurementScheduleRequest schedule, Map<String, Object> stats,
Date lastResetTime, Date collectionTime) throws Exception {
CallTimeData previousRawCallTimeData = this.previousRawCallTimeDatas.get(schedule.getScheduleId());
CallTimeData rawCallTimeData = new CallTimeData(schedule);
this.previousRawCallTimeDatas.put(schedule.getScheduleId(), rawCallTimeData);
CallTimeData callTimeData = new CallTimeData(schedule);
for (String methodName : stats.keySet()) {
Object timeStatistic = stats.get(methodName);
long minTime = (Long) timeStatistic.getClass().getField("minTime").get(timeStatistic);
long maxTime = (Long) timeStatistic.getClass().getField("maxTime").get(timeStatistic);
long totalTime = (Long) timeStatistic.getClass().getField("totalTime").get(timeStatistic);
long count = (Long) timeStatistic.getClass().getField("count").get(timeStatistic);
try {
rawCallTimeData.addAggregatedCallData(methodName, lastResetTime, collectionTime, minTime, maxTime,
totalTime, count);
} catch (IllegalArgumentException iae) {
// if any issue with the data, log them and continue processing the rest of the report
log.error(iae);
continue;
}
// Now compute the adjusted data, which is what we will report back to the server.
CallTimeDataValue previousValue = (previousRawCallTimeData != null) ? previousRawCallTimeData.getValues()
.get(methodName) : null;
boolean supercedesPrevious = ((previousValue != null) && (previousValue.getBeginTime() == lastResetTime
.getTime()));
Date beginTime = lastResetTime;
if (supercedesPrevious) {
// The data for this method hasn't been reset since the last time we collected it.
long countSincePrevious = count - previousValue.getCount();
if (countSincePrevious > 0) {
// There have been new calls since the last time we collected data
// for this method. Adjust the time span to begin at the end of the
// time span from the previous collection.
beginTime = new Date(previousValue.getEndTime());
// Adjust the total and count to reflect the adjusted time span;
// do so by subtracting the previous values from the current values.
// NOTE: It isn't possible to figure out the minimum and maximum for
// the adjusted time span, so just leave them be. If they happen
// to have changed since the previous collection, they will be
// accurate; otherwise they will not.
count = countSincePrevious;
totalTime = totalTime - (long) previousValue.getTotal();
}
// else, the count hasn't changed, so don't bother adjusting the data;
// when the JON server sees the data has the same begin time as
// previously persisted data, it will replace the previous data with the
// updated data (which will basically have a later end time)
}
callTimeData.addAggregatedCallData(methodName, beginTime, collectionTime, minTime, maxTime, totalTime,
count);
}
return callTimeData;
}