You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/01/26 17:22:19 UTC

[GitHub] [nifi] markap14 commented on a change in pull request #5703: NIFI-9620: Adding isStateful to StatelessDataflow

markap14 commented on a change in pull request #5703:
URL: https://github.com/apache/nifi/pull/5703#discussion_r792868996



##########
File path: nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/flow/StandardStatelessFlow.java
##########
@@ -521,6 +522,26 @@ private void executeDataflow(final BlockingQueue<TriggerResult> resultQueue, fin
         }
     }
 
+    @Override
+    public boolean isStateful() {
+        return isStateful(rootGroup);
+    }
+
+    private boolean isStateful(final ProcessGroup processGroup) {
+        boolean isStateful = processGroup.getProcessors().stream()
+                .filter(processorNode -> processorNode.getProcessor().getClass().getAnnotation(Stateful.class) != null)
+                .findAny()
+                .isPresent();

Review comment:
       Can simplify this a bit, i think, to:
   ```
   boolean stateful = processGroup.getProcessors().stream()
       .anyMatch( processorNode -> processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class));
   ```
   no?

##########
File path: nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/flow/StandardStatelessFlow.java
##########
@@ -521,6 +522,26 @@ private void executeDataflow(final BlockingQueue<TriggerResult> resultQueue, fin
         }
     }
 
+    @Override
+    public boolean isStateful() {
+        return isStateful(rootGroup);
+    }
+
+    private boolean isStateful(final ProcessGroup processGroup) {
+        boolean isStateful = processGroup.getProcessors().stream()
+                .filter(processorNode -> processorNode.getProcessor().getClass().getAnnotation(Stateful.class) != null)
+                .findAny()
+                .isPresent();
+
+        if (isStateful) {
+            return true;
+        }
+
+        return processGroup.getProcessGroups().stream()
+                .filter(childGroup -> isStateful(childGroup))
+                .findAny()
+                .isPresent();

Review comment:
       Think we can simplify this in much the same way:
   ```
   return processGroup.getProcessGroups().stream()
       .anyMatch(this::isStateful);
   ```

##########
File path: nifi-stateless/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/flow/StandardStatelessFlow.java
##########
@@ -521,6 +522,26 @@ private void executeDataflow(final BlockingQueue<TriggerResult> resultQueue, fin
         }
     }
 
+    @Override
+    public boolean isStateful() {
+        return isStateful(rootGroup);

Review comment:
       Not sure how frequently this will be called. But since the value won't change from call to call, wondering if it makes sense to lazily initialize this and just cache the value in a member variable?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org