55 lines
1.2 KiB
Java
55 lines
1.2 KiB
Java
package org.gcube.accounting.datamodel.aggregation.scheduler;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.accounting.datamodel.UsageRecord;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
*
|
|
*/
|
|
public abstract class AggregationScheduler {
|
|
|
|
protected static AggregationScheduler aggregationScheduler;
|
|
|
|
public static AggregationScheduler getInstance(){
|
|
if(aggregationScheduler==null){
|
|
aggregationScheduler = new BufferAggregationScheduler();
|
|
}
|
|
return aggregationScheduler;
|
|
}
|
|
|
|
protected List<UsageRecord> records;
|
|
|
|
/**
|
|
* @return the records
|
|
*/
|
|
public List<UsageRecord> getRecords() {
|
|
return records;
|
|
}
|
|
|
|
protected AggregationScheduler(){
|
|
this.records = new ArrayList<UsageRecord>();
|
|
}
|
|
|
|
protected void madeAggregation(UsageRecord UsageRecord){
|
|
// TODO
|
|
}
|
|
|
|
/**
|
|
* Get an usage records and try to aggregate with other buffered
|
|
* Usage Record.
|
|
* @param usageRecord the Usage Record To Buffer
|
|
* @return true if is time to persist the buffered Usage Record
|
|
*/
|
|
public synchronized boolean aggregate(UsageRecord UsageRecord) {
|
|
madeAggregation(UsageRecord);
|
|
return isTimeToPersist();
|
|
}
|
|
|
|
|
|
protected abstract boolean isTimeToPersist();
|
|
|
|
}
|