src/share/classes/sun/management/ManagementFactoryHelper.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -25,10 +25,11 @@
 
 package sun.management;
 
 import java.lang.management.*;
 
+import javax.management.DynamicMBean;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.MBeanRegistrationException;
 import javax.management.NotCompliantMBeanException;

@@ -40,11 +41,13 @@
 
 import sun.util.logging.LoggingSupport;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import com.sun.management.DiagnosticCommandMBean;
 import com.sun.management.OSMBeanFactory;
 import com.sun.management.HotSpotDiagnosticMXBean;
 
 import static java.lang.management.ManagementFactory.*;
 

@@ -261,10 +264,11 @@
     private static HotspotRuntime hsRuntimeMBean = null;
     private static HotspotClassLoading hsClassMBean = null;
     private static HotspotThread hsThreadMBean = null;
     private static HotspotCompilation hsCompileMBean = null;
     private static HotspotMemory hsMemoryMBean = null;
+    private static DiagnosticCommandImpl hsDiagCommandMBean = null;
 
     public static synchronized HotSpotDiagnosticMXBean getDiagnosticMXBean() {
         if (hsDiagMBean == null) {
             hsDiagMBean = new HotSpotDiagnostic();
         }

@@ -309,10 +313,18 @@
             hsMemoryMBean = new HotspotMemory(jvm);
         }
         return hsMemoryMBean;
     }
 
+    public static synchronized DiagnosticCommandMBean getDiagnosticCommandMBean() {
+        // Remote Diagnostic Commands may not be supported
+        if (hsDiagCommandMBean == null && jvm.isRemoteDiagnosticCommandsSupported()) {
+            hsDiagCommandMBean = new DiagnosticCommandImpl(jvm);
+        }
+        return hsDiagCommandMBean;
+    }
+
     /**
      * This method is for testing only.
      */
     public static synchronized HotspotCompilationMBean getHotspotCompilationMBean() {
         if (hsCompileMBean == null) {

@@ -363,10 +375,21 @@
         "sun.management:type=HotspotRuntime";
 
     private final static String HOTSPOT_THREAD_MBEAN_NAME =
         "sun.management:type=HotspotThreading";
 
+    final static String HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME =
+        "com.sun.management:type=DiagnosticCommand";
+
+    public static HashMap<ObjectName, DynamicMBean> getPlatformDynamicMBeans() {
+        HashMap<ObjectName, DynamicMBean> map = new HashMap<>();
+        if (getDiagnosticCommandMBean() != null) {
+            map.put(Util.newObjectName(HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME), getDiagnosticCommandMBean());
+        }
+        return map;
+    }
+
     static void registerInternalMBeans(MBeanServer mbs) {
         // register all internal MBeans if not registered
         // No exception is thrown if a MBean with that object name
         // already registered
         addMBean(mbs, getHotspotClassLoadingMBean(),