Synchronize methods for rules 92/104992/1
authorJim Hahn <jrh3@att.com>
Thu, 2 Apr 2020 13:57:52 +0000 (09:57 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 2 Apr 2020 13:57:52 +0000 (09:57 -0400)
Added "synchronized" to a few more methods in the event manager class,
just to be safe, as they view/modify data that may be viewed/modified
by other threads.

Issue-ID: POLICY-2385
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: Ia8404fd3fd53b0de95f939dfff2088867e0f3b24

controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java

index 05563ca..cc54b73 100644 (file)
@@ -249,7 +249,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
     /**
      * Starts the next step, whatever that may be.
      */
-    public void nextStep() {
+    public synchronized void nextStep() {
         if (!isActive()) {
             return;
         }
@@ -280,7 +280,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      *
      * @return {@code true} if the manager is still active, {@code false} otherwise
      */
-    public boolean isActive() {
+    public synchronized boolean isActive() {
         return (createdByThisJvmInstance && finalResult == null);
     }
 
@@ -355,7 +355,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
     /**
      * Cancels the current operation and frees all locks.
      */
-    public void destroy() {
+    public synchronized void destroy() {
         ControlLoopOperationManager2 oper = currentOperation.get();
         if (oper != null) {
             oper.cancel();
@@ -376,7 +376,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      *
      * @return a new notification
      */
-    public VirtualControlLoopNotification makeNotification() {
+    public synchronized VirtualControlLoopNotification makeNotification() {
         VirtualControlLoopNotification notif = new VirtualControlLoopNotification(context.getEvent());
         notif.setNotification(ControlLoopNotificationType.OPERATION);
         notif.setFrom("policy");
@@ -400,7 +400,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      * @param event the event
      * @return the status
      */
-    public NewEventStatus onNewEvent(VirtualControlLoopEvent event) {
+    public synchronized NewEventStatus onNewEvent(VirtualControlLoopEvent event) {
         try {
             checkEventSyntax(event);
 
@@ -446,7 +446,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      * @param event the event syntax
      * @throws ControlLoopException if an error occurs
      */
-    public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
+    protected void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
         validateStatus(event);
         if (StringUtils.isBlank(event.getClosedLoopControlName())) {
             throw new ControlLoopException("No control loop name");
@@ -514,7 +514,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      * @return <code>true</code> if the control loop is disabled, <code>false</code>
      *         otherwise
      */
-    public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
+    private static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
         Map<String, String> aai = event.getAai();
         return (isAaiTrue(aai.get(VSERVER_IS_CLOSED_LOOP_DISABLED))
                         || isAaiTrue(aai.get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED))
@@ -528,7 +528,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      * @return {@code true} if the provisioning status is neither ACTIVE nor {@code null},
      *         {@code false} otherwise
      */
-    protected static boolean isProvStatusInactive(VirtualControlLoopEvent event) {
+    private static boolean isProvStatusInactive(VirtualControlLoopEvent event) {
         Map<String, String> aai = event.getAai();
         return !(PROV_STATUS_ACTIVE.equals(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE))
                         && PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE)));
@@ -541,7 +541,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
      * @return the boolean value represented by the field value, or {@code false} if the
      *         value is {@code null}
      */
-    protected static boolean isAaiTrue(String aaiValue) {
+    private static boolean isAaiTrue(String aaiValue) {
         return (aaiValue != null && TRUE_VALUES.contains(aaiValue.toLowerCase()));
     }