Use AtomicInteger and other sonar 75/104575/1
authorPamela Dragosh <pdragosh@research.att.com>
Fri, 27 Mar 2020 15:12:11 +0000 (11:12 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Fri, 27 Mar 2020 15:12:16 +0000 (11:12 -0400)
Removed unused logger.
Added NOSONAR to main to remove security risk, as we do
validate arguments.
Used AtomicInteger.

Issue-ID: POLICY-2305
Change-Id: I18e91836e914b7fd6e3cd9a950dca58fcd8be5b5
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java

index 2c67633..c842bd2 100644 (file)
@@ -142,11 +142,11 @@ public class Main {
     }
 
     /**
-     * The main method.
+     * The main method. The args passed in are validated in the constructor, thus adding the NOSONAR.
      *
      * @param args the arguments
      */
-    public static void main(final String[] args) {
+    public static void main(final String[] args) { // NOSONAR
         new Main(args);
     }
 }
index b89a679..5d011f0 100644 (file)
@@ -27,7 +27,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-
+import java.util.concurrent.atomic.AtomicInteger;
 import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.model.Csar;
 import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
@@ -60,7 +60,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
     private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED;
     private IDistributionClient distributionClient;
     private SdcConfiguration sdcConfig;
-    private volatile int nbOfNotificationsOngoing = 0;
+    private AtomicInteger nbOfNotificationsOngoing = new AtomicInteger();
     private int retryDelay;
     private SdcClientHandler sdcClientHandler;
 
@@ -109,7 +109,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
                 handleIdleStatusChange(newStatus);
                 break;
             case BUSY:
-                ++nbOfNotificationsOngoing;
+                nbOfNotificationsOngoing.incrementAndGet();
                 sdcReceptionHandlerStatus = newStatus;
                 break;
             default:
@@ -370,10 +370,10 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
      * @param newStatus the new status
      */
     private void handleIdleStatusChange(final SdcReceptionHandlerStatus newStatus) {
-        if (nbOfNotificationsOngoing > 1) {
-            --nbOfNotificationsOngoing;
+        if (nbOfNotificationsOngoing.get() > 1) {
+            nbOfNotificationsOngoing.decrementAndGet();
         } else {
-            nbOfNotificationsOngoing = 0;
+            nbOfNotificationsOngoing.set(0);
             sdcReceptionHandlerStatus = newStatus;
         }
     }
index 5067c84..aa822e7 100644 (file)
@@ -36,16 +36,12 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
 import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
 import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Handles the plugins to policy distribution.
  */
 public class PluginHandler {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(PluginHandler.class);
-
     private Collection<PolicyDecoder<PolicyInput, ToscaEntity>> policyDecoders;
     private Collection<PolicyForwarder> policyForwarders;