*/
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();
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();
*/
@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);
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();
}
});
}