timeabarna commented on a change in pull request #5115:
URL: https://github.com/apache/nifi/pull/5115#discussion_r644502293



##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
##########
@@ -90,14 +91,20 @@
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = 
Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", 
"ZHeap");

Review comment:
       Thanks @Lehel44 converted the list to unmodifiable

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
##########
@@ -90,14 +91,20 @@
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = 
Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", 
"ZHeap");
     private static final AllowableValue[] memPoolAllowableValues;
+    private static String defaultMemoryPool;
 
     static {
         // Only allow memory pool beans that support usage thresholds, 
otherwise we wouldn't report anything anyway
         List<MemoryPoolMXBean> memoryPoolBeans = 
ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
         memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
         for (int i = 0; i < memPoolAllowableValues.length; i++) {
-            memPoolAllowableValues[i] = new 
AllowableValue(memoryPoolBeans.get(i).getName());
+            final String poolName = memoryPoolBeans.get(i).getName();

Review comment:
       Converted the code to stream with a minor modification on you suggestion 
as Array contains AllowableValues not string, so a conversion needed first.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
##########
@@ -90,14 +91,20 @@
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = 
Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", 
"ZHeap");
     private static final AllowableValue[] memPoolAllowableValues;
+    private static String defaultMemoryPool;
 
     static {
         // Only allow memory pool beans that support usage thresholds, 
otherwise we wouldn't report anything anyway
         List<MemoryPoolMXBean> memoryPoolBeans = 
ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
         memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
         for (int i = 0; i < memPoolAllowableValues.length; i++) {
-            memPoolAllowableValues[i] = new 
AllowableValue(memoryPoolBeans.get(i).getName());
+            final String poolName = memoryPoolBeans.get(i).getName();
+            if (defaultMemoryPool == null && 
GC_OLD_GEN_POOLS.contains(poolName)) {

Review comment:
       With the stream refactor this part is no longer applicable however the 
goal was to stop looking for the default value after we found it 
(defaultMemoryPool = poolName;).

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
##########
@@ -90,14 +91,20 @@
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = 
Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", 
"ZHeap");
     private static final AllowableValue[] memPoolAllowableValues;
+    private static String defaultMemoryPool;
 
     static {
         // Only allow memory pool beans that support usage thresholds, 
otherwise we wouldn't report anything anyway
         List<MemoryPoolMXBean> memoryPoolBeans = 
ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
         memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
         for (int i = 0; i < memPoolAllowableValues.length; i++) {
-            memPoolAllowableValues[i] = new 
AllowableValue(memoryPoolBeans.get(i).getName());
+            final String poolName = memoryPoolBeans.get(i).getName();

Review comment:
       Thanks @Lehel44 Converted the code to stream with a minor modification 
on your suggestion, as Array contains AllowableValues not string, a conversion 
needed first.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
##########
@@ -90,14 +91,20 @@
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = 
Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", 
"ZHeap");
     private static final AllowableValue[] memPoolAllowableValues;
+    private static String defaultMemoryPool;
 
     static {
         // Only allow memory pool beans that support usage thresholds, 
otherwise we wouldn't report anything anyway
         List<MemoryPoolMXBean> memoryPoolBeans = 
ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
         memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
         for (int i = 0; i < memPoolAllowableValues.length; i++) {
-            memPoolAllowableValues[i] = new 
AllowableValue(memoryPoolBeans.get(i).getName());
+            final String poolName = memoryPoolBeans.get(i).getName();
+            if (defaultMemoryPool == null && 
GC_OLD_GEN_POOLS.contains(poolName)) {

Review comment:
       Thanks @Lehel44 With the stream refactor this part is no longer 
applicable however the goal was to stop looking for the default value after we 
found it (defaultMemoryPool = poolName;).




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