JeetKunDoug commented on code in PR #2318:
URL: https://github.com/apache/cassandra/pull/2318#discussion_r1202745797


##########
src/java/org/apache/cassandra/utils/MBeanWrapper.java:
##########
@@ -170,6 +186,125 @@ public void unregisterMBean(ObjectName mbeanName, 
OnException onException)
         }
     }
 
+    static class InstanceMBeanWrapper implements MBeanWrapper
+    {
+        private final MBeanServer mbs;
+        public final UUID id = UUID.randomUUID();
+
+        public InstanceMBeanWrapper(String hostname)
+        {
+            mbs = MBeanServerFactory.createMBeanServer(hostname + "-" + id);
+        }
+
+        public void registerMBean(Object obj, ObjectName mbeanName, 
OnException onException)
+        {
+            try
+            {
+                mbs.registerMBean(obj, mbeanName);
+            }
+            catch (Exception e)
+            {
+                onException.handler.accept(e);
+            }
+        }
+
+        public boolean isRegistered(ObjectName mbeanName, OnException 
onException)
+        {
+            try
+            {
+                return mbs.isRegistered(mbeanName);
+            }
+            catch (Exception e)
+            {
+                onException.handler.accept(e);
+            }
+            return false;
+        }
+
+        public void unregisterMBean(ObjectName mbeanName, OnException 
onException)
+        {
+            try
+            {
+                mbs.unregisterMBean(mbeanName);
+            }
+            catch (Exception e)
+            {
+                onException.handler.accept(e);
+            }
+        }
+
+        public MBeanServer getMBeanServer()
+        {
+            return mbs;
+        }
+
+        public void close() {
+            mbs.queryNames(null, null).forEach(name -> {
+                try {
+                    if 
(!name.getCanonicalName().contains("MBeanServerDelegate"))
+                        mbs.unregisterMBean(name);
+                } catch (Throwable e) {
+                    logger.debug("Could not unregister mbean {}", 
name.getCanonicalName());

Review Comment:
   I don't think it's necessary - it generally happens because it's already 
been unregistered elsewhere (so it's actually not a huge problem, was more 
there for, well, debugging), and it would be super-verbose.



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

Reply via email to