public MeteringSummaryGenerationDSStub getStub(){
return meteringStub;
}
public Calendar getLatestSummaryTime(int summaryPeriod, int serverId) throws BAMException{
BAMCalendar cal = null;
try {
SummaryTime[] time;
switch (summaryPeriod) {
case BAMCalendar.HOUR_OF_DAY:
time = meteringStub.getLatestHourlyBandwidthSummaryPeriodId(serverId);
break;
case BAMCalendar.DAY_OF_MONTH:
time = meteringStub.getLatestDailyBandwidthSummaryPeriodId(serverId);
break;
case BAMCalendar.MONTH:
time = meteringStub.getLatestMonthlyBandwidthSummaryPeriodId(serverId);
break;
case BAMCalendar.QUATER:
time = meteringStub.getLatestQuarterlyBandwidthSummaryPeriodId(serverId);
break;
case BAMCalendar.YEAR:
time = meteringStub.getLatestYearlyBandwidthSummaryPeriodId(serverId);
break;
default:
throw new BAMException("Unexpected timeInterval");
}
if (time != null && time[0] != null) {
//we are sure that there will be only one record.
cal = BAMCalendar.getInstance(time[0].getStartTime());
}else {
//This is the first time we are running the summary. So, get the minimum time stamp
//for this server from "server user data" table
time = meteringStub.getMinimumPeriodId(serverId);
if (time != null && time[0] != null) {
//we are sure that there will be only one record.
cal = BAMCalendar.getInstance(time[0].getStartTime());
}else{
//We are running for the first time and there are no records in
//"server user data". So, we can start from now
cal = BAMCalendar.getInstance();
}
//Start with last period so that it will include our intended period
cal.add(summaryPeriod, -2);
}
} catch (Exception e) {
String msg = "Unable to get LatestSummaryTime";
log.error(msg);