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



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-stateless-bundle/nifi-stateless-engine/src/main/java/org/apache/nifi/stateless/config/PropertiesFileFlowDefinitionParser.java
##########
@@ -207,6 +221,73 @@
         return new ArrayList<>(contextDefinitions.values());
     }
 
+    private TransactionThresholds getTransactionThresholds(final Map<String, 
String> properties) {
+        final Long flowfileThreshold = getLongProperty(properties, 
TRANSACTION_THRESHOLD_FLOWFILES);
+        final Double dataSizeThreshold = getDataSizeProperty(properties, 
TRANSACTION_THRESHOLD_DATA_SIZE, DataUnit.B);
+        final Double timeThreshold = getTimePeriodProperty(properties, 
TRANSACTION_THRESHOLD_TIME, TimeUnit.NANOSECONDS);
+
+        final OptionalLong maxFlowFiles = flowfileThreshold == null ? 
OptionalLong.empty() : OptionalLong.of(flowfileThreshold);
+        final OptionalLong maxBytes = dataSizeThreshold == null ? 
OptionalLong.empty() : OptionalLong.of(dataSizeThreshold.longValue());
+        final OptionalLong maxNanos = timeThreshold == null ? 
OptionalLong.empty() : OptionalLong.of(timeThreshold.longValue());
+
+        return new TransactionThresholds() {
+            @Override
+            public OptionalLong getMaxFlowFiles() {
+                return maxFlowFiles;
+            }
+
+            @Override
+            public OptionalLong getMaxContentSize(final DataUnit dataUnit) {
+                return maxBytes;
+            }
+
+            @Override
+            public OptionalLong getMaxTime(final TimeUnit timeUnit) {
+                return maxNanos;
+            }
+        };
+    }
+
+    private Long getLongProperty(final Map<String, String> properties, final 
String propertyName) {
+        final String propertyValue = properties.get(propertyName);
+        if (propertyValue == null || propertyValue.trim().isEmpty()) {
+            return null;
+        }
+
+        try {
+            return Long.parseLong(propertyValue.trim());
+        } catch (final NumberFormatException nfe) {
+            throw new IllegalArgumentException("Configured property <" + 
propertyName + "> has a value that is not a valid 64-bit integer");
+        }
+    }

Review comment:
       Good call.




-- 
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.

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


Reply via email to