Fixed fallback file when context is null

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@124248 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-17 13:11:59 +00:00
parent ad305923d2
commit 1f102a3813
2 changed files with 22 additions and 6 deletions

View File

@ -66,6 +66,17 @@ public abstract class PersistenceBackendFactory {
}
}
protected synchronized static String getFallbackLocation(){
if(fallbackLocation==null){
try {
return System.getProperty(HOME_SYSTEM_PROPERTY);
}catch(Exception e){
return ".";
}
}
return fallbackLocation;
}
protected static String sanitizeContext(String context){
return context.replace("/", "_");
}
@ -74,9 +85,9 @@ public abstract class PersistenceBackendFactory {
File fallbackFile = null;
if(context!=null){
String sanitized = sanitizeContext(context);
fallbackFile = new File(fallbackLocation, String.format("%s.%s", sanitized, FALLBACK_FILENAME));
fallbackFile = new File(getFallbackLocation(), String.format("%s.%s", sanitized, FALLBACK_FILENAME));
}else{
fallbackFile = new File(fallbackLocation, FALLBACK_FILENAME);
fallbackFile = new File(getFallbackLocation(), FALLBACK_FILENAME);
}
return fallbackFile;
}
@ -84,6 +95,7 @@ public abstract class PersistenceBackendFactory {
protected static FallbackPersistenceBackend createFallback(String context){
logger.debug("Creating {} for context {}", FallbackPersistenceBackend.class.getSimpleName(), context);
File fallbackFile = getFallbackFile(context);
logger.trace("{} for context {} is {}", FallbackPersistenceBackend.class.getSimpleName(), context, fallbackFile.getAbsolutePath());
FallbackPersistenceBackend fallbackPersistence = new FallbackPersistenceBackend(fallbackFile);
fallbackPersistence.setAggregationScheduler(AggregationScheduler.newInstance(new DefaultPersitenceExecutor(fallbackPersistence)));
return fallbackPersistence;
@ -180,8 +192,10 @@ public abstract class PersistenceBackendFactory {
public static PersistenceBackend getPersistenceBackend(String context) {
if(context==null){
logger.error("No Context available. FallbackPersistence will be used");
return createFallback(null);
logger.warn("No Context available. FallbackPersistence will be used");
FallbackPersistenceBackend fallbackPersistenceBackend = createFallback(null);
persistenceBackends.put(null, fallbackPersistenceBackend);
return fallbackPersistenceBackend;
}
PersistenceBackend persistence = null;
@ -218,7 +232,7 @@ public abstract class PersistenceBackendFactory {
logger.debug("Flushing records in context {}", context);
apb.flush(timeout, timeUnit);
}catch(Exception e){
logger.error("Unable to flush records in context {} with {}", context, apb);
logger.error("Unable to flush records in context {} with {}", context, apb, e);
}
}

View File

@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@SuppressWarnings({ "rawtypes" })
public abstract class RecordUtility {
public class RecordUtility {
private static Logger logger = LoggerFactory.getLogger(RecordUtility.class);
@ -27,6 +27,8 @@ public abstract class RecordUtility {
private final static String KEY_VALUE_PAIR_SEPARATOR = ",";
private final static String KEY_VALUE_LINKER = "=";
private RecordUtility(){}
protected static Map<String, Class<? extends Record>> recordClassesFound;
protected static Map<String, Class<? extends AggregatedRecord>> aggregatedRecordClassesFound;