Fire AbstractPrerequisite listeners as soon as they resolve 91/93991/2
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:54:46 +0000 (18:54 +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>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModifierImpl.java

index 5926a0634684c8b339fe0eb96e46efbdb6b2d917..1c636a937df61573ef7299634a899d390c389198 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;
@@ -314,7 +311,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();
         }
     }
 
@@ -343,7 +340,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
@@ -420,7 +417,9 @@ final class ModifierImpl implements ModelActionBuilder {
 
             if (!it.hasNext()) {
                 // Last step: we are done
-                resolvePrereq((C) value);
+                if (resolvePrereq((C) value)) {
+                    tryApply();
+                }
                 return;
             }