Author: orudyy
Date: Thu Feb 18 17:30:51 2016
New Revision: 1731099

URL: http://svn.apache.org/viewvc?rev=1731099&view=rev
Log:
QPID-7081: [Java Broker] On broker startup with IBM JDK log message 'Cannot 
find com.sun.management.HotSpotDiagnosticMXBean MXBean' only once

Modified:
    
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java

Modified: 
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java?rev=1731099&r1=1731098&r2=1731099&view=diff
==============================================================================
--- 
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
 (original)
+++ 
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/BrokerAttributeInjector.java
 Thu Feb 18 17:30:51 2016
@@ -56,6 +56,30 @@ public class BrokerAttributeInjector imp
                 }
             };
 
+    private final Class<?> _hotSpotDiagnosticMXBeanClass;
+    private final PlatformManagedObject _hotSpotDiagnosticMXBean;
+
+    public BrokerAttributeInjector()
+    {
+        Class<?> hotSpotDiagnosticMXBeanClass = null;
+        PlatformManagedObject hotSpotDiagnosticMXBean = null;
+        try
+        {
+            ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+            hotSpotDiagnosticMXBeanClass =
+                    
Class.forName("com.sun.management.HotSpotDiagnosticMXBean", true, 
systemClassLoader);
+            hotSpotDiagnosticMXBean =
+                    ManagementFactory.getPlatformMXBean((Class<? extends 
PlatformManagedObject>) hotSpotDiagnosticMXBeanClass);
+
+        }
+        catch (ClassNotFoundException e)
+        {
+            LOGGER.debug("Cannot find 
com.sun.management.HotSpotDiagnosticMXBean MXBean: " + e);
+        }
+
+        _hotSpotDiagnosticMXBeanClass = hotSpotDiagnosticMXBeanClass;
+        _hotSpotDiagnosticMXBean = hotSpotDiagnosticMXBean;
+    }
 
     @Override
     public Collection<ConfiguredObjectInjectedAttribute<?, ?>> 
getInjectedAttributes()
@@ -182,45 +206,34 @@ public class BrokerAttributeInjector imp
     {
         List<ConfiguredObjectInjectedOperation<?>> operations = new 
ArrayList<>();
 
-        try
+        if (_hotSpotDiagnosticMXBean != null)
         {
-            ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
-            final Class<?> hotSpotDiagnosticMXBeanClass =
-                    
Class.forName("com.sun.management.HotSpotDiagnosticMXBean", true, 
systemClassLoader);
-            final PlatformManagedObject hotSpotDiagnosticMXBean =
-                    ManagementFactory.getPlatformMXBean((Class<? extends 
PlatformManagedObject>) hotSpotDiagnosticMXBeanClass);
-
-            ConfiguredObjectInjectedOperation<?> setJVMOptions =
-                    injectSetJVMOptions(hotSpotDiagnosticMXBeanClass, 
hotSpotDiagnosticMXBean);
-            if (setJVMOptions != null)
+            try
+            {
+                operations.add(injectSetJVMOptions());
+            }
+            catch (NoSuchMethodException e)
             {
-                operations.add(setJVMOptions);
+                LOGGER.warn("Failed to inject operation setJVMOptions", e);
             }
 
-            ConfiguredObjectInjectedOperation<?> heapDump =
-                    injectDumpHeap(hotSpotDiagnosticMXBeanClass, 
hotSpotDiagnosticMXBean);
-            if (heapDump != null)
+            try
             {
-                operations.add(heapDump);
+                operations.add(injectDumpHeap());
+            }
+            catch (NoSuchMethodException e)
+            {
+                LOGGER.warn("Failed to inject operation dumpHeap", e);
             }
-        }
-        catch (ClassNotFoundException e)
-        {
-            LOGGER.warn("Cannot find 
com.sun.management.HotSpotDiagnosticMXBean MXBean: " + e.getMessage());
         }
 
-
         return operations;
     }
 
-    private ConfiguredObjectInjectedOperation<?> injectDumpHeap(
-            final Class<?> hotSpotDiagnosticMXBeanClass,
-            final PlatformManagedObject hotSpotDiagnosticMXBean)
+    private ConfiguredObjectInjectedOperation<?> injectDumpHeap() throws 
NoSuchMethodException
     {
-        try
-        {
             Method heapDumpMethod =
-                    hotSpotDiagnosticMXBeanClass.getDeclaredMethod("dumpHeap", 
String.class, boolean.class);
+                    
_hotSpotDiagnosticMXBeanClass.getDeclaredMethod("dumpHeap", String.class, 
boolean.class);
 
             Method method = 
BrokerAttributeInjector.class.getDeclaredMethod("dumpHeap",
                                                                             
Broker.class,
@@ -249,25 +262,16 @@ public class BrokerAttributeInjector imp
                     true,
                     params,
                     method,
-                    new Object[]{hotSpotDiagnosticMXBean, heapDumpMethod},
+                    new Object[]{_hotSpotDiagnosticMXBean, heapDumpMethod},
                     _typeValidator);
             return setVMOptionOperation;
-        }
-        catch (NoSuchMethodException e)
-        {
-            LOGGER.warn("Failed to inject operation dumpHeap", e);
-        }
-        return null;
     }
 
-    private ConfiguredObjectInjectedOperation<?> injectSetJVMOptions(
-            final Class<?> hotSpotDiagnosticMXBeanClass,
-            final PlatformManagedObject hotSpotDiagnosticMXBean)
+    private ConfiguredObjectInjectedOperation<?> injectSetJVMOptions() throws 
NoSuchMethodException
     {
-        try
-        {
+
             Method setVMOptionMethod =
-                    
hotSpotDiagnosticMXBeanClass.getDeclaredMethod("setVMOption", String.class, 
String.class);
+                    
_hotSpotDiagnosticMXBeanClass.getDeclaredMethod("setVMOption", String.class, 
String.class);
 
             Method method = 
BrokerAttributeInjector.class.getDeclaredMethod("setJVMOptions",
                                                                             
Broker.class,
@@ -288,15 +292,9 @@ public class BrokerAttributeInjector imp
                     true,
                     params,
                     method,
-                    new Object[]{hotSpotDiagnosticMXBean, setVMOptionMethod},
+                    new Object[]{_hotSpotDiagnosticMXBean, setVMOptionMethod},
                     _typeValidator);
             return setVMOptionOperation;
-        }
-        catch (NoSuchMethodException e)
-        {
-            LOGGER.warn("Failed to inject operation setJVMOptions", e);
-        }
-        return null;
     }
 
     @Override



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to