Fire AbstractPrerequisite listeners as soon as they resolve 93/93993/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Dec 2020 13:42:15 +0000 (14:42 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Dec 2020 17:55:57 +0000 (18:55 +0100)
We seem to be stuck with listeners not firing, leaving references
which need to be cleared. Ensure we fire phase listeners as soon
as they are satisfied -- repurposing tryApply() for its logical
purpose.

JIRA: YANGTOOLS-1192
Change-Id: I87d1700e2cc80bfa3fbb5be9a8dc938d6fe55c17
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d70f2e9f13755ea7c3aac1f0c8d8a6b0b0861368)

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModifierImpl.java

index 7327e988af32d362801e90586d423ecb8fa8200a..5edde2ffd80a3b391b6c6d86331cce5b11fb27a7 100644 (file)
@@ -86,12 +86,6 @@ final class ModifierImpl implements ModelActionBuilder {
         action = null;
     }
 
-    private void applyAction() {
-        checkState(!actionApplied);
-        action.apply(ctx);
-        actionApplied = true;
-    }
-
     private <K, C extends StmtContext<?, ?, ?>, N extends StatementNamespace<K, ?, ?>> @NonNull AbstractPrerequisite<C>
             requiresCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key,
                     final ModelProcessingPhase phase)  {
@@ -147,7 +141,10 @@ final class ModifierImpl implements ModelActionBuilder {
         checkState(action != null, "Action was not defined yet.");
 
         if (removeSatisfied()) {
-            applyAction();
+            if (!actionApplied) {
+                action.apply(ctx);
+                actionApplied = true;
+            }
             return true;
         }
         return false;
@@ -320,7 +317,7 @@ final class ModifierImpl implements ModelActionBuilder {
         @Override
         public boolean phaseFinished(final StatementContextBase<?, ?, ?> context,
                 final ModelProcessingPhase finishedPhase) {
-            return resolvePrereq((C) context);
+            return resolvePrereq((C) context) || tryApply();
         }
     }
 
@@ -349,7 +346,7 @@ final class ModifierImpl implements ModelActionBuilder {
         @Override
         public boolean phaseFinished(final StatementContextBase<?, ?, ?> context,
                 final ModelProcessingPhase finishedPhase) {
-            return resolvePrereq((C) context);
+            return resolvePrereq((C) context) || tryApply();
         }
 
         @Override
@@ -426,7 +423,9 @@ final class ModifierImpl implements ModelActionBuilder {
 
             if (!it.hasNext()) {
                 // Last step: we are done
-                resolvePrereq((C) value);
+                if (resolvePrereq((C) value)) {
+                    tryApply();
+                }
                 return;
             }