diff options
author | Lianhao Lu <lianhao.lu@intel.com> | 2019-04-12 08:53:46 +0800 |
---|---|---|
committer | Lianhao Lu <lianhao.lu@intel.com> | 2019-04-12 08:53:46 +0800 |
commit | 9c24d662337f0c2043fbd8e6dc7a91fb2b299dff (patch) | |
tree | 4d3502aca6914baabb978c689112d351f4ea8df3 | |
parent | c82614f968fb7941f7778873afa3bfad51ffd42f (diff) |
Fix sonnar issues
Change-Id: Ic9ad2d733ace26fdd085a03af901783192d72a79
Issue-ID: POLICY-1638
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
2 files changed, 14 insertions, 18 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java index 4115bff3..d02d9bba 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java @@ -88,9 +88,8 @@ public class FilePolicyForwarder implements PolicyForwarder { */ private void forwardPolicy(final OptimizationPolicy pol) throws PolicyForwardingException { final String name = pol.getPolicyName(); - try { - Path path = Paths.get(fileForwarderParameters.getPath(), name); - BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString())); + Path path = Paths.get(fileForwarderParameters.getPath(), name); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString()))) { writer.write("policyName: " + name); if (fileForwarderParameters.isVerbose()) { writer.newLine(); @@ -112,7 +111,6 @@ public class FilePolicyForwarder implements PolicyForwarder { writer.newLine(); writer.write("riskType: " + pol.getRiskType()); } - writer.close(); LOGGER.debug("Sucessfully forwarded the policy to store into file {}.", path); } catch (final InvalidPathException | IOException exp) { final String message = "Error sending policy to file under path:" + fileForwarderParameters.getPath(); 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 56bca900..72341ee5 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 @@ -115,8 +115,7 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { */ @SuppressWarnings("unchecked") protected void startWatchService(final WatchService watcher, - final Path dir, - int maxThread) throws InterruptedException, NullPointerException, IllegalArgumentException { + final Path dir, int maxThread) throws InterruptedException { WatchKey key; ExecutorService pool = Executors.newFixedThreadPool(maxThread); @@ -128,18 +127,17 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { 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); - } + pool.execute(() -> { + 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); + Thread.currentThread().interrupt(); } }); } |