Add new method shutdown

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@144456 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Alessandro Pieve 2017-03-01 10:24:34 +00:00
parent b73f53cd50
commit 5c3fdbbe6b
3 changed files with 82 additions and 44 deletions

View File

@ -9,7 +9,7 @@
<groupId>org.gcube.data.publishing</groupId>
<artifactId>document-store-lib</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
<name>Document Store Lib</name>
<description>Allow to persist data in NoSQL Document Store Databases.
Discover Model dynamically.

View File

@ -27,4 +27,6 @@ public class ExecutorUtils {
}
});
}

View File

@ -299,4 +299,40 @@ public abstract class PersistenceBackendFactory {
}
/**
*
*/
public static void shutdown() {
//shutdown the scheduler
ExecutorUtils.scheduler.shutdown();
try {
ExecutorUtils.scheduler.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
logger.error("Unable to shutdown the scheduler", e);
}
//shutdown the threadPool
ExecutorUtils.threadPool.shutdown();
try {
ExecutorUtils.threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
logger.error("Unable to shutdown the threadPool", e);
}
//disconnect the persistence and clean
for(String context : persistenceBackends.keySet()){
context = sanitizeContext(context);
PersistenceBackend apb;
synchronized (persistenceBackends) {
apb = persistenceBackends.get(context);
}
try {
logger.debug("Flushing records in context {}", context);
apb.closeAndClean();
}catch(Exception e){
logger.error("Unable to flush records in context {} with {}", context, apb, e);
}
}
}
}