From a45f8909871dc1ddb75845f067a602951afc8d11 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 19 Feb 2018 16:56:06 -0500 Subject: Sonar fixes to drools-pdp Fixed most of the instances of the following sonar issues: Moved array designator Used diamond operator Changed System.out/err to use a logger Changed several Thread.sleep() in test code to a single sleep() Useless assignments Replaced comparison with "" to string.isEmpty() Merged if's Replaced ArrayList with List in method returns Reordered type modifiers Reordered constructor methods Defined constants for literals, or replaced them with method calls Removed "throws Xxx" for subclasses of RuntimeException Combined identical "catch" blocks Re-interrupted the current thread after catching an InterruptedException Removed tests against the literal "false" Fix indentation of new makeTopicOperError() method. Fix exception variable name in new methods, logNoUebEncoder() and logNoDmaapEncoder(). Change-Id: Iddae5210553662f733b67333b372dec8c3fe2c94 Issue-ID: POLICY-336 Signed-off-by: Jim Hahn --- .../onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'feature-simulators') diff --git a/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java b/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java index bdabc6ee..2513a040 100644 --- a/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java +++ b/feature-simulators/src/main/java/org/onap/policy/drools/simulators/DMaaPSimulatorJaxRs.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * feature-simulators * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory; @Path("/events") public class DMaaPSimulatorJaxRs { + private static final String NO_DATA_MSG = "No Data"; private static final Map> queues = new ConcurrentHashMap<>(); private static final Logger logger = LoggerFactory.getLogger(DMaaPSimulatorJaxRs.class); private static int responseCode = 200; @@ -57,7 +58,6 @@ public class DMaaPSimulatorJaxRs { try { httpResponse.flushBuffer(); } catch (IOException e) { - final Logger logger = LoggerFactory.getLogger(DMaaPSimulatorJaxRs.class); logger.error("flushBuffer threw: ", e); return "Got an error"; } @@ -68,14 +68,15 @@ public class DMaaPSimulatorJaxRs { } if (queues.containsKey(topicName)) { BlockingQueue queue = queues.get(topicName); - String response = "No Data"; + String response = NO_DATA_MSG; try { response = queue.poll(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logger.debug("error in DMaaP simulator", e); + Thread.currentThread().interrupt(); } if (response == null) { - response = "No Data"; + response = NO_DATA_MSG; } return response; } @@ -86,12 +87,13 @@ public class DMaaPSimulatorJaxRs { BlockingQueue queue = queues.get(topicName); String response = queue.poll(); if (response == null) { - response = "No Data"; + response = NO_DATA_MSG; } return response; } } catch (InterruptedException e) { logger.debug("error in DMaaP simulator", e); + Thread.currentThread().interrupt(); } } return "No topic"; -- cgit 1.2.3-korg