From 4445ec9df7552fa8cb23a4616366366400c9a475 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 17 Nov 2015 11:15:16 +0000 Subject: [PATCH] refs #1282: New Accounting: IS-Collector doesn't start correctly after upgrade to ghn 6.0.0 https://support.d4science.org/issues/1282 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120288 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingPersistenceBackendFactory.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java index f039caa..785202b 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java @@ -119,30 +119,35 @@ public abstract class AccountingPersistenceBackendFactory { logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.", AccountingPersistenceBackend.class.getSimpleName(), scope, actual.getClass().getSimpleName()); - AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope); - if(discoveredPersistenceBackend!=null){ - // Passing the aggregator to the new AccountingPersistenceBackend - // so that the buffered records will be persisted with the new method - discoveredPersistenceBackend.setAggregationScheduler(actual.getAggregationScheduler()); - - // Removing timestamp wich is no more needed - fallbackLastCheck.remove(scope); - accountingPersistenceBackends.put(scope, discoveredPersistenceBackend); - try { - actual.close(); - } catch (Exception e) { - logger.error("Error closing {} for scope {} which has been substituted with {}.", - actual.getClass().getSimpleName(), scope, - discoveredPersistenceBackend.getClass().getSimpleName(), e); - } - return discoveredPersistenceBackend; - - }else{ - // Renewing timestamp - logger.trace("Renewing Last check Timestamp. The new one will be {}", now); + lock.lock(); + try { + logger.trace("Renewing Last check Timestamp. The next one will be {}", now); fallbackLastCheck.put(scope, now); lastCheckTimestamp = fallbackLastCheck.get(scope); + + AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope); + if(discoveredPersistenceBackend!=null){ + // Passing the aggregator to the new AccountingPersistenceBackend + // so that the buffered records will be persisted with the new method + discoveredPersistenceBackend.setAggregationScheduler(actual.getAggregationScheduler()); + + // Removing timestamp wich is no more needed + fallbackLastCheck.remove(scope); + accountingPersistenceBackends.put(scope, discoveredPersistenceBackend); + try { + actual.close(); + } catch (Exception e) { + logger.error("Error closing {} for scope {} which has been substituted with {}.", + actual.getClass().getSimpleName(), scope, + discoveredPersistenceBackend.getClass().getSimpleName(), e); + } + lock.unlock(); + return discoveredPersistenceBackend; + } + }finally { + lock.unlock(); } + } long nextCheck = (lastCheckTimestamp + FALLBACK_RETRY_TIME) - Calendar.getInstance().getTimeInMillis(); @@ -184,14 +189,9 @@ public abstract class AccountingPersistenceBackendFactory { lock.unlock(); } - lock.lock(); - try { - persistence = accountingPersistenceBackends.get(scope); - if(persistence instanceof FallbackPersistenceBackend){ - persistence = rediscoverAccountingPersistenceBackend(persistence, scope); - } - } finally { - lock.unlock(); + persistence = accountingPersistenceBackends.get(scope); + if(persistence instanceof FallbackPersistenceBackend){ + persistence = rediscoverAccountingPersistenceBackend(persistence, scope); } return persistence;