From b316a78e8e93de1628f4ed215d5c52dbf5ff0d14 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 19 Nov 2015 15:03:14 +0000 Subject: [PATCH] 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 --- .../persistence/AccountingPersistenceBackendMonitor.java | 8 +++++++- .../persistence/FallbackPersistenceBackend.java | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java index 10a9940..0563f62 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java @@ -45,7 +45,13 @@ public class AccountingPersistenceBackendMonitor implements Runnable { UsageRecord usageRecord = BasicUsageRecord.getUsageRecord(line); accountingPersistenceBackend.accountWithFallback(usageRecord); } 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) { diff --git a/src/main/java/org/gcube/accounting/persistence/FallbackPersistenceBackend.java b/src/main/java/org/gcube/accounting/persistence/FallbackPersistenceBackend.java index 448a15d..eb96297 100644 --- a/src/main/java/org/gcube/accounting/persistence/FallbackPersistenceBackend.java +++ b/src/main/java/org/gcube/accounting/persistence/FallbackPersistenceBackend.java @@ -48,18 +48,22 @@ public class FallbackPersistenceBackend extends AccountingPersistenceBackend { */ @Override protected void reallyAccount(UsageRecord usageRecord) throws Exception { + printLine(String.valueOf( usageRecord)); + } + + public void printLine(String line) throws Exception { synchronized (accountingFallbackFile) { try(FileWriter fw = new FileWriter(accountingFallbackFile, true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)){ - out.println(usageRecord); + out.println(line); out.flush(); } catch( IOException e ){ throw e; } } } - + /** * {@inheritDoc} */