Restored unpatched version for IC
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120227 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fc9b9bb023
commit
fe78dc48f1
|
@ -8,7 +8,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;
|
||||||
|
@ -30,10 +29,6 @@ public abstract class AccountingPersistenceBackendFactory {
|
||||||
|
|
||||||
private static String fallbackLocation;
|
private static String fallbackLocation;
|
||||||
|
|
||||||
private static ReentrantLock lock = new ReentrantLock();
|
|
||||||
|
|
||||||
private static ReentrantLock persistenceLock = new ReentrantLock();
|
|
||||||
|
|
||||||
private static Map<String, AccountingPersistenceBackend> persistencePersistenceBackends;
|
private static Map<String, AccountingPersistenceBackend> persistencePersistenceBackends;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -54,23 +49,17 @@ public abstract class AccountingPersistenceBackendFactory {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void setFallbackLocation(String path){
|
protected synchronized static void setFallbackLocation(String path){
|
||||||
lock.lock();
|
if(fallbackLocation == null){
|
||||||
try{
|
if(path==null){
|
||||||
if(fallbackLocation == null){
|
path = System.getProperty(HOME_SYSTEM_PROPERTY);
|
||||||
if(path==null){
|
|
||||||
path = System.getProperty(HOME_SYSTEM_PROPERTY);
|
|
||||||
}
|
|
||||||
file(new File(path));
|
|
||||||
fallbackLocation = path;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}finally{
|
file(new File(path));
|
||||||
lock.unlock();
|
fallbackLocation = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static AccountingPersistenceBackend getPersistenceBackend() {
|
protected static synchronized AccountingPersistenceBackend getPersistenceBackend() {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
if(scope==null){
|
if(scope==null){
|
||||||
logger.error("No Scope available. FallbackPersistence will be used");
|
logger.error("No Scope available. FallbackPersistence will be used");
|
||||||
|
@ -78,28 +67,19 @@ public abstract class AccountingPersistenceBackendFactory {
|
||||||
return new FallbackPersistence(fallbackFile);
|
return new FallbackPersistence(fallbackFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
persistenceLock.lock();
|
|
||||||
AccountingPersistenceBackend persistence = persistencePersistenceBackends.get(scope);
|
AccountingPersistenceBackend persistence = persistencePersistenceBackends.get(scope);
|
||||||
if(persistence==null){
|
if(persistence==null){
|
||||||
FallbackPersistence fallbackPersistence;
|
|
||||||
try{
|
|
||||||
ScopeBean bean = new ScopeBean(scope);
|
|
||||||
/*
|
|
||||||
if(bean.is(Type.VRE)){
|
|
||||||
bean = bean.enclosingScope();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
String name = bean.name();
|
|
||||||
|
|
||||||
File fallbackFile = new File(fallbackLocation, String.format("%s.%s", name, ACCOUTING_FALLBACK_FILENAME));
|
ScopeBean bean = new ScopeBean(scope);
|
||||||
fallbackPersistence = new FallbackPersistence(fallbackFile);
|
/*
|
||||||
// set only to avoid deadlock
|
if(bean.is(Type.VRE)){
|
||||||
persistencePersistenceBackends.put(scope, fallbackPersistence);
|
bean = bean.enclosingScope();
|
||||||
}finally{
|
|
||||||
persistenceLock.unlock();
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
String name = bean.name();
|
||||||
|
|
||||||
|
File fallbackFile = new File(fallbackLocation, String.format("%s.%s", name, ACCOUTING_FALLBACK_FILENAME));
|
||||||
|
FallbackPersistence fallbackPersistence = new FallbackPersistence(fallbackFile);
|
||||||
try {
|
try {
|
||||||
ServiceLoader<AccountingPersistenceBackend> serviceLoader = ServiceLoader.load(AccountingPersistenceBackend.class);
|
ServiceLoader<AccountingPersistenceBackend> serviceLoader = ServiceLoader.load(AccountingPersistenceBackend.class);
|
||||||
for (AccountingPersistenceBackend foundPersistence : serviceLoader) {
|
for (AccountingPersistenceBackend foundPersistence : serviceLoader) {
|
||||||
|
@ -135,11 +115,8 @@ public abstract class AccountingPersistenceBackendFactory {
|
||||||
persistence.setAggregationScheduler(AggregationScheduler.newInstance());
|
persistence.setAggregationScheduler(AggregationScheduler.newInstance());
|
||||||
persistence.setFallback(fallbackPersistence);
|
persistence.setFallback(fallbackPersistence);
|
||||||
persistencePersistenceBackends.put(scope, persistence);
|
persistencePersistenceBackends.put(scope, persistence);
|
||||||
} else{
|
|
||||||
persistenceLock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return persistence;
|
return persistence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue