brusdev commented on code in PR #5952:
URL: https://github.com/apache/activemq-artemis/pull/5952#discussion_r2413915007


##########
artemis-commons/src/main/java/org/apache/activemq/artemis/utils/critical/CriticalAnalyzerImpl.java:
##########
@@ -49,28 +52,53 @@ public CriticalAnalyzerImpl() {
        *  otherwise in case of a deadlock, or a starvation of the server the 
analyzer won't pick up any
        *  issues and won't be able to shutdown the server or halt the VM
        */
-      this.scheduledComponent = new ActiveMQScheduledComponent(null, null, 
checkTimeNanoSeconds, TimeUnit.NANOSECONDS, false) {
+      this.scheduledComponent = new CriticalAnalyzerScheduledComponent(this, 
null, null, checkTimeNanoSeconds, checkTimeNanoSeconds, TimeUnit.NANOSECONDS, 
false);
 
-         @Override
-         public void run() {
-            logger.trace("Checking critical analyzer");
-            check();
-         }
+   }
 
-         @Override
-         protected ActiveMQThreadFactory getThreadFactory() {
-            return new ActiveMQThreadFactory("critical-analyzer", true, 
getThisClassLoader());
-         }
+   private static class CriticalAnalyzerScheduledComponent extends 
ActiveMQScheduledComponent {
 
-         private ClassLoader getThisClassLoader() {
-            return 
AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> 
CriticalAnalyzerImpl.this.getClass().getClassLoader());
+      private final CriticalAnalyzerImpl criticalAnalyzer;
 
-         }
+      public CriticalAnalyzerScheduledComponent(CriticalAnalyzerImpl 
criticalAnalyzer,
+                                                ScheduledExecutorService 
scheduledExecutorService,
+                                                Executor executor,
+                                                long initialDelay,
+                                                long checkPeriod,
+                                                TimeUnit timeUnit,
+                                                boolean onDemand) {
+         super(scheduledExecutorService, executor, initialDelay, checkPeriod, 
timeUnit, onDemand);
+         this.criticalAnalyzer = criticalAnalyzer;
+      }
+
+
+      @Override
+      public void run() {
+         logger.trace("Checking critical analyzer");
+         criticalAnalyzer.check();
+      }
+
+      @Override
+      protected ActiveMQThreadFactory getThreadFactory() {
+         return new ActiveMQThreadFactory("critical-analyzer", true, 
getThisClassLoader());
+      }
+
+      private ClassLoader getThisClassLoader() {
+         return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) 
() -> criticalAnalyzer.getClass().getClassLoader());
+      }
+
+      /** Schedule an action to kick in the critical analyzer.
+       *  If this future is not cancelled in time, the critical analyzer will 
kick in. */
+      public ScheduledFuture<?> kickIt(CriticalComponent component) {
+         return scheduledExecutorService.schedule(() -> {
+            criticalAnalyzer.fireActions(component);
+         }, period, timeUnit);
+      }

Review Comment:
   LGTM



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to