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:
parent
976f9f21f7
commit
b771e6bb2e
|
@ -33,12 +33,26 @@ public abstract class PersistenceBackendFactory {
|
||||||
private static String fallbackLocation;
|
private static String fallbackLocation;
|
||||||
|
|
||||||
private static Map<String, PersistenceBackend> persistenceBackends;
|
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 INITIAL_DELAY = 1000; // 1 min
|
||||||
public static final long FALLBACK_RETRY_TIME = 1000*60*10; // 10 min
|
public static final long FALLBACK_RETRY_TIME = 1000*60*10; // 10 min
|
||||||
|
|
||||||
static {
|
static {
|
||||||
persistenceBackends = new HashMap<String, PersistenceBackend>();
|
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) {
|
public static void addRecordPackage(Package packageObject) {
|
||||||
|
@ -144,12 +158,15 @@ public abstract class PersistenceBackendFactory {
|
||||||
public static PersistenceBackend getPersistenceBackend(String context) {
|
public static PersistenceBackend getPersistenceBackend(String context) {
|
||||||
context = sanitizeContext(context);
|
context = sanitizeContext(context);
|
||||||
|
|
||||||
|
Boolean forceImmediateRediscovery = getForceImmediateRediscovery(context);
|
||||||
|
|
||||||
PersistenceBackend persistence = null;
|
PersistenceBackend persistence = null;
|
||||||
logger.trace("Going to synchronized block in getPersistenceBackend");
|
logger.trace("Going to synchronized block in getPersistenceBackend");
|
||||||
synchronized (persistenceBackends) {
|
synchronized (persistenceBackends) {
|
||||||
persistence = persistenceBackends.get(context);
|
persistence = persistenceBackends.get(context);
|
||||||
logger.trace("{} {}", PersistenceBackend.class.getSimpleName(), persistence);
|
logger.trace("{} {}", PersistenceBackend.class.getSimpleName(), persistence);
|
||||||
if(persistence==null){
|
if(persistence==null){
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setting FallbackPersistence and unlocking.
|
* Setting FallbackPersistence and unlocking.
|
||||||
* There will be another thread which will try to discover the
|
* There will be another thread which will try to discover the
|
||||||
|
@ -158,11 +175,16 @@ public abstract class PersistenceBackendFactory {
|
||||||
persistence = createFallback(context);
|
persistence = createFallback(context);
|
||||||
persistenceBackends.put(context, persistence);
|
persistenceBackends.put(context, persistence);
|
||||||
|
|
||||||
|
if(forceImmediateRediscovery){
|
||||||
|
persistence = discoverPersistenceBackend(context);
|
||||||
|
persistenceBackends.put(context, persistence);
|
||||||
|
}else{
|
||||||
new PersistenceBackendRediscover(context,
|
new PersistenceBackendRediscover(context,
|
||||||
(FallbackPersistenceBackend) persistence, INITIAL_DELAY,
|
(FallbackPersistenceBackend) persistence, INITIAL_DELAY,
|
||||||
FALLBACK_RETRY_TIME, TimeUnit.MILLISECONDS);
|
FALLBACK_RETRY_TIME, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return persistence;
|
return persistence;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue