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