aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main/java/org/onap/policy
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2019-04-11 10:26:45 +0800
committerLianhao Lu <lianhao.lu@intel.com>2019-04-11 10:26:45 +0800
commitc82614f968fb7941f7778873afa3bfad51ffd42f (patch)
treea7de1c1647d9b799a707ae7a8943a3f82e10d1d9 /plugins/reception-plugins/src/main/java/org/onap/policy
parent87f514006bc79fa977a9924039e0f5b8e70a9e6b (diff)
Gracefully release resource in file reception plugin
In the FileSystemReception plugin, we need to shutdown the thread pool to release the resources gracefully. Change-Id: I800e4070d7bf8c052d964139117a68dc48c50f76 Issue-ID: POLICY-1631 Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Diffstat (limited to 'plugins/reception-plugins/src/main/java/org/onap/policy')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java53
1 files changed, 28 insertions, 25 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java
index 0ddd2a92..56bca900 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java
@@ -120,35 +120,38 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
WatchKey key;
ExecutorService pool = Executors.newFixedThreadPool(maxThread);
- running = true;
- while (running) {
- key = watcher.take();
+ try {
+ running = true;
+ while (running) {
+ key = watcher.take();
- for (final WatchEvent<?> event : key.pollEvents()) {
- final WatchEvent<Path> ev = (WatchEvent<Path>) event;
- final Path fileName = ev.context();
- pool.execute(new Runnable() {
- public void run() {
- LOGGER.debug("new CSAR found: {}", fileName);
- DistributionStatisticsManager.updateTotalDistributionCount();
- final String fullFilePath = dir.toString() + File.separator + fileName.toString();
- try {
- waitForFileToBeReady(fullFilePath);
- createPolicyInputAndCallHandler(fullFilePath);
- LOGGER.debug("CSAR complete: {}", fileName);
- } catch (InterruptedException e) {
- LOGGER.error("waitForFileToBeReady interrupted", e);
+ for (final WatchEvent<?> event : key.pollEvents()) {
+ final WatchEvent<Path> ev = (WatchEvent<Path>) event;
+ final Path fileName = ev.context();
+ pool.execute(new Runnable() {
+ public void run() {
+ LOGGER.debug("new CSAR found: {}", fileName);
+ DistributionStatisticsManager.updateTotalDistributionCount();
+ final String fullFilePath = dir.toString() + File.separator + fileName.toString();
+ try {
+ waitForFileToBeReady(fullFilePath);
+ createPolicyInputAndCallHandler(fullFilePath);
+ LOGGER.debug("CSAR complete: {}", fileName);
+ } catch (InterruptedException e) {
+ LOGGER.error("waitForFileToBeReady interrupted", e);
+ }
}
- }
- });
- }
- final boolean valid = key.reset();
- if (!valid) {
- LOGGER.error("Watch key no longer valid!");
- break;
+ });
+ }
+ final boolean valid = key.reset();
+ if (!valid) {
+ LOGGER.error("Watch key no longer valid!");
+ break;
+ }
}
+ } finally {
+ pool.shutdown();
}
- pool.shutdown();
}
/**