Adde the posisbility to force the rediscovery immeditly for that applciation that need the right Persitence at statup.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@134507 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-11-22 11:08:52 +00:00
parent 976f9f21f7
commit b771e6bb2e
1 changed files with 25 additions and 3 deletions

View File

@ -33,12 +33,26 @@ public abstract class PersistenceBackendFactory {
private static String fallbackLocation;
private static Map<String, PersistenceBackend> persistenceBackends;
private static Map<String, Boolean> forceImmediateRediscoveries;
public static final long INITIAL_DELAY = 1000; // 1 min
public static final long FALLBACK_RETRY_TIME = 1000*60*10; // 10 min
static {
persistenceBackends = new HashMap<String, PersistenceBackend>();
forceImmediateRediscoveries = new HashMap<>();
}
public static void forceImmediateRediscovery(String context){
forceImmediateRediscoveries.put(context, new Boolean(true));
}
public static Boolean getForceImmediateRediscovery(String context){
Boolean force = forceImmediateRediscoveries.get(context);
if(force==null){
force=new Boolean(false);
}
return force;
}
public static void addRecordPackage(Package packageObject) {
@ -144,12 +158,15 @@ public abstract class PersistenceBackendFactory {
public static PersistenceBackend getPersistenceBackend(String context) {
context = sanitizeContext(context);
Boolean forceImmediateRediscovery = getForceImmediateRediscovery(context);
PersistenceBackend persistence = null;
logger.trace("Going to synchronized block in getPersistenceBackend");
synchronized (persistenceBackends) {
persistence = persistenceBackends.get(context);
logger.trace("{} {}", PersistenceBackend.class.getSimpleName(), persistence);
if(persistence==null){
/*
* Setting FallbackPersistence and unlocking.
* There will be another thread which will try to discover the
@ -158,9 +175,14 @@ public abstract class PersistenceBackendFactory {
persistence = createFallback(context);
persistenceBackends.put(context, persistence);
new PersistenceBackendRediscover(context,
(FallbackPersistenceBackend) persistence, INITIAL_DELAY,
FALLBACK_RETRY_TIME, TimeUnit.MILLISECONDS);
if(forceImmediateRediscovery){
persistence = discoverPersistenceBackend(context);
persistenceBackends.put(context, persistence);
}else{
new PersistenceBackendRediscover(context,
(FallbackPersistenceBackend) persistence, INITIAL_DELAY,
FALLBACK_RETRY_TIME, TimeUnit.MILLISECONDS);
}
}
}