Removed reentrant lock using syncronized instead

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120300 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-11-18 11:30:35 +00:00
parent 907f2b9707
commit 4b9bbd779e
1 changed files with 3 additions and 16 deletions

View File

@ -9,7 +9,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.gcube.accounting.aggregation.scheduler.AggregationScheduler;
import org.gcube.common.scope.api.ScopeProvider;
@ -31,7 +30,6 @@ public abstract class AccountingPersistenceBackendFactory {
private static String fallbackLocation;
private static ReentrantLock lock = new ReentrantLock();
private static Map<String, AccountingPersistenceBackend> accountingPersistenceBackends;
private static Map<String, Long> fallbackLastCheck;
@ -118,9 +116,9 @@ 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);
try {
lock.lock();
synchronized (accountingPersistenceBackends) {
logger.trace("Renewing Last check Timestamp. The next one will be {}", now);
Long reCheckTimestamp = fallbackLastCheck.get(scope);
if(lastCheckTimestamp.compareTo(reCheckTimestamp)!=0){
@ -129,11 +127,6 @@ public abstract class AccountingPersistenceBackendFactory {
return actual;
}
fallbackLastCheck.put(scope, now);
lock.unlock();
AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope);
lock.lock();
if(discoveredPersistenceBackend!=null){
// Passing the aggregator to the new AccountingPersistenceBackend
// so that the buffered records will be persisted with the new method
@ -149,11 +142,8 @@ public abstract class AccountingPersistenceBackendFactory {
actual.getClass().getSimpleName(), scope,
discoveredPersistenceBackend.getClass().getSimpleName(), e);
}
lock.unlock();
return discoveredPersistenceBackend;
}
}finally {
lock.unlock();
}
}
@ -175,9 +165,8 @@ public abstract class AccountingPersistenceBackendFactory {
return createFallback(null);
}
lock.lock();
AccountingPersistenceBackend persistence = null;
try {
synchronized (accountingPersistenceBackends) {
persistence = accountingPersistenceBackends.get(scope);
if(persistence==null){
/*
@ -193,8 +182,6 @@ public abstract class AccountingPersistenceBackendFactory {
*/
fallbackLastCheck.put(scope, ((now - FALLBACK_RETRY_TIME) - 1));
}
} finally {
lock.unlock();
}
persistence = accountingPersistenceBackends.get(scope);