refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Implementing buffer strategy git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115720 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
bbf40324f8
commit
9318f46c28
|
@ -111,6 +111,8 @@ public abstract class AggregationScheduler {
|
||||||
for(AggregationStrategy aggregationStrategy : aggregationStrategies){
|
for(AggregationStrategy aggregationStrategy : aggregationStrategies){
|
||||||
try {
|
try {
|
||||||
aggregationStrategy.aggregate((SingleUsageRecord) usageRecord);
|
aggregationStrategy.aggregate((SingleUsageRecord) usageRecord);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
} catch(NotAggregatableRecordsExceptions e) {
|
} catch(NotAggregatableRecordsExceptions e) {
|
||||||
logger.trace("{} is not usable for aggregation", aggregationStrategy);
|
logger.trace("{} is not usable for aggregation", aggregationStrategy);
|
||||||
}
|
}
|
||||||
|
@ -155,16 +157,16 @@ public abstract class AggregationScheduler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void flush(PersistenceExecutor persistenceExecutor) throws Exception{
|
||||||
* Get an usage records and try to aggregate with other buffered
|
aggregate(null, persistenceExecutor, true);
|
||||||
* Usage Record.
|
}
|
||||||
* @param usageRecord the Usage Record To Buffer
|
|
||||||
* @return true if is time to persist the buffered Usage Record
|
protected synchronized void aggregate(SingleUsageRecord usageRecord, PersistenceExecutor persistenceExecutor, boolean forceFlush) throws Exception {
|
||||||
* @throws Exception if fails
|
if(usageRecord!=null){
|
||||||
*/
|
|
||||||
public synchronized void aggregate(SingleUsageRecord usageRecord, PersistenceExecutor persistenceExecutor) throws Exception {
|
|
||||||
madeAggregation(usageRecord);
|
madeAggregation(usageRecord);
|
||||||
if(isTimeToPersist()){
|
}
|
||||||
|
|
||||||
|
if(isTimeToPersist() || forceFlush){
|
||||||
UsageRecord[] recordToPersist = new UsageRecord[totalBufferedRecords];
|
UsageRecord[] recordToPersist = new UsageRecord[totalBufferedRecords];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -186,7 +188,17 @@ public abstract class AggregationScheduler {
|
||||||
records.clear();
|
records.clear();
|
||||||
unaggregableRecords.clear();
|
unaggregableRecords.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @throws Exception if fails
|
||||||
|
*/
|
||||||
|
public void aggregate(SingleUsageRecord usageRecord, PersistenceExecutor persistenceExecutor) throws Exception {
|
||||||
|
aggregate(usageRecord, persistenceExecutor, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,18 @@ public abstract class Persistence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void flush() throws Exception {
|
||||||
|
aggregationScheduler.flush(new PersistenceExecutor(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void persist(UsageRecord... usageRecords) throws Exception {
|
||||||
|
persistence.accountWithFallback(usageRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract void close() throws Exception;
|
public abstract void close() throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public class PersistenceTest {
|
||||||
double average = (duration/quantity);
|
double average = (duration/quantity);
|
||||||
logger.debug("Duration (in millisec) : " + duration);
|
logger.debug("Duration (in millisec) : " + duration);
|
||||||
logger.debug("Average (in millisec) : " + average);
|
logger.debug("Average (in millisec) : " + average);
|
||||||
|
|
||||||
|
persistence.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue