From 7121248817f972305171ace287e00dee6cbdf960 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 18 Nov 2015 11:55:14 +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@120301 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingPersistenceBackendFactory.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java index 5d4b8ca..728393f 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java @@ -116,6 +116,7 @@ public abstract class AccountingPersistenceBackendFactory { if( (lastCheckTimestamp + FALLBACK_RETRY_TIME) <= now ){ 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); synchronized (accountingPersistenceBackends) { @@ -123,25 +124,36 @@ public abstract class AccountingPersistenceBackendFactory { Long reCheckTimestamp = fallbackLastCheck.get(scope); if(lastCheckTimestamp.compareTo(reCheckTimestamp)!=0){ // Someone else arrived here before. Stopping to try to - logger.debug("Someone else arrived here before. Stopping to try to rediscover AccountingPersistenceBackend"); - return actual; + logger.debug("Someone else arrived here before. Stopping to try to rediscover AccountingPersistenceBackend and getting the current"); + return accountingPersistenceBackends.get(scope); } + fallbackLastCheck.put(scope, now); if(discoveredPersistenceBackend!=null){ - // Passing the aggregator to the new AccountingPersistenceBackend - // so that the buffered records will be persisted with the new method + /* + * 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 + // Removing timestamp which 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); - } + + /* + * Not needed because close has no effect. Removed to + * prevent problem in cases of future changes. + * 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; } } @@ -184,7 +196,6 @@ public abstract class AccountingPersistenceBackendFactory { } } - persistence = accountingPersistenceBackends.get(scope); if(persistence instanceof FallbackPersistenceBackend){ persistence = rediscoverAccountingPersistenceBackend(persistence, scope); }