Fixing code to support retry

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120321 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-11-19 15:03:14 +00:00
parent 492d32550e
commit b316a78e8e
2 changed files with 13 additions and 3 deletions

View File

@ -45,7 +45,13 @@ public class AccountingPersistenceBackendMonitor implements Runnable {
UsageRecord usageRecord = BasicUsageRecord.getUsageRecord(line); UsageRecord usageRecord = BasicUsageRecord.getUsageRecord(line);
accountingPersistenceBackend.accountWithFallback(usageRecord); accountingPersistenceBackend.accountWithFallback(usageRecord);
} catch(Exception e){ } catch(Exception e){
logger.error("Line {} will be lost", line, e); logger.error("Was not possible parse line {} to obtain a valid UsageRecord. Going to writing back this line as string fallback file.", line, e);
FallbackPersistenceBackend fallbackPersistenceBackend = accountingPersistenceBackend.getFallbackPersistence();
try {
fallbackPersistenceBackend.printLine(line);
} catch (Exception e1) {
logger.error("Was not possible Line {} will be lost", line, e1);
}
} }
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View File

@ -48,18 +48,22 @@ public class FallbackPersistenceBackend extends AccountingPersistenceBackend {
*/ */
@Override @Override
protected void reallyAccount(UsageRecord usageRecord) throws Exception { protected void reallyAccount(UsageRecord usageRecord) throws Exception {
printLine(String.valueOf( usageRecord));
}
public void printLine(String line) throws Exception {
synchronized (accountingFallbackFile) { synchronized (accountingFallbackFile) {
try(FileWriter fw = new FileWriter(accountingFallbackFile, true); try(FileWriter fw = new FileWriter(accountingFallbackFile, true);
BufferedWriter bw = new BufferedWriter(fw); BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)){ PrintWriter out = new PrintWriter(bw)){
out.println(usageRecord); out.println(line);
out.flush(); out.flush();
} catch( IOException e ){ } catch( IOException e ){
throw e; throw e;
} }
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */