aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2018-11-13 11:25:29 +0800
committerLianhao Lu <lianhao.lu@intel.com>2018-11-13 18:56:14 +0800
commit3c0823e37b6cf933b23687a2d7339b131fe5a464 (patch)
tree50b2fc8b9a3dd3ff23f8e93ec25688506e700bf0 /plugins/reception-plugins/src/main
parent47cfce72ef448023acbd9724d4597eb084055405 (diff)
FileSystemReceptionHandler: Fix sonar issues
Fixed 6 code smell issues reported by sonar. Change-Id: I537df24f0f0624470efd8675f01ecd433aed1cb0 Issue-ID: POLICY-1256 Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Diffstat (limited to 'plugins/reception-plugins/src/main')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java73
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java2
2 files changed, 39 insertions, 36 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
index b1a95fac..db0b0b7b 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
@@ -43,7 +43,7 @@ import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
* Handles reception of inputs from File System which can be used to decode policies.
*/
public class FileSystemReceptionHandler extends AbstractReceptionHandler {
- private boolean running = true;
+ private boolean running = false;
private static final Logger LOGGER = FlexLogger.getLogger(FileSystemReceptionHandler.class);
@Override
@@ -56,6 +56,7 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
} catch (final Exception ex) {
LOGGER.error(ex);
}
+ running = false;
LOGGER.debug("FileSystemReceptionHandler main loop exited...");
}
@@ -65,53 +66,57 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler {
running = false;
}
+ public boolean isRunning() {
+ return running;
+ }
+
/**
* Main entry point.
*
* @param watchPath Path to watch
*/
@SuppressWarnings("unchecked")
- public void main(String watchPath) {
+ public void main(String watchPath) throws IOException {
try (final WatchService watcher = FileSystems.getDefault().newWatchService()) {
final Path dir = Paths.get(watchPath);
-
dir.register(watcher, ENTRY_CREATE);
LOGGER.debug("Watch Service registered for dir: " + dir.getFileName());
- while (running) {
- WatchKey key;
- try {
- key = watcher.take();
- } catch (final InterruptedException ex) {
- LOGGER.debug(ex);
- Thread.currentThread().interrupt();
- return;
- }
+ startMainLoop(watcher, dir);
+ } catch (final InterruptedException ex) {
+ LOGGER.debug(ex);
+ Thread.currentThread().interrupt();
+ }
+ }
- for (final WatchEvent<?> event : key.pollEvents()) {
- final WatchEvent.Kind<?> kind = event.kind();
- final WatchEvent<Path> ev = (WatchEvent<Path>) event;
- final Path fileName = ev.context();
- try {
- LOGGER.debug("new CSAR found: " + kind.name() + ": " + fileName);
- createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString());
- LOGGER.debug("CSAR complete: " + kind.name() + ": " + fileName);
- } catch (final PolicyDecodingException ex) {
- LOGGER.error(ex);
- }
- }
- final boolean valid = key.reset();
- if (!valid) {
- LOGGER.error("Watch key no longer valid!");
- break;
- }
+ @SuppressWarnings("unchecked")
+ protected void startMainLoop(WatchService watcher, Path dir) throws InterruptedException {
+ WatchKey key;
+ running = true;
+ while (running) {
+ key = watcher.take();
+
+ for (final WatchEvent<?> event : key.pollEvents()) {
+ final WatchEvent.Kind<?> kind = event.kind();
+ final WatchEvent<Path> ev = (WatchEvent<Path>) event;
+ final Path fileName = ev.context();
+ LOGGER.debug("new CSAR found: " + fileName);
+ createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString());
+ LOGGER.debug("CSAR complete: " + fileName);
+ }
+ final boolean valid = key.reset();
+ if (!valid) {
+ LOGGER.error("Watch key no longer valid!");
+ break;
}
- } catch (final IOException ex) {
- LOGGER.error(ex);
}
}
- protected void createPolicyInputAndCallHandler(final String fileName) throws PolicyDecodingException {
- final Csar csarObject = new Csar(fileName);
- inputReceived(csarObject);
+ protected void createPolicyInputAndCallHandler(final String fileName) {
+ try {
+ final Csar csarObject = new Csar(fileName);
+ inputReceived(csarObject);
+ } catch (final PolicyDecodingException ex) {
+ LOGGER.error(ex);
+ }
}
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java
index b017cae6..37a16980 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java
@@ -20,8 +20,6 @@
package org.onap.policy.distribution.reception.handling.sdc;
-import java.util.List;
-
/**
* This class builds an instance of {@link FileSystemReceptionHandlerConfigurationParameterGroup} class.
*