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

Print this page




  29 
  30 import javax.management.DynamicMBean;
  31 import javax.management.InstanceAlreadyExistsException;
  32 import javax.management.InstanceNotFoundException;
  33 import javax.management.MBeanServer;
  34 import javax.management.MBeanRegistrationException;
  35 import javax.management.NotCompliantMBeanException;
  36 import javax.management.ObjectName;
  37 import javax.management.RuntimeOperationsException;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedActionException;
  40 import java.security.PrivilegedExceptionAction;
  41 
  42 import sun.util.logging.LoggingSupport;
  43 
  44 import java.util.ArrayList;
  45 import java.util.Collections;
  46 import java.util.HashMap;
  47 import java.util.List;
  48 import com.sun.management.DiagnosticCommandMBean;
  49 import com.sun.management.OSMBeanFactory;
  50 import com.sun.management.HotSpotDiagnosticMXBean;
  51 
  52 import static java.lang.management.ManagementFactory.*;
  53 
  54 /**
  55  * ManagementFactoryHelper provides static factory methods to create
  56  * instances of the management interface.
  57  */
  58 public class ManagementFactoryHelper {
  59     private ManagementFactoryHelper() {};
  60 
  61     private static VMManagement jvm;
  62 
  63     private static ClassLoadingImpl    classMBean = null;
  64     private static MemoryImpl          memoryMBean = null;
  65     private static ThreadImpl          threadMBean = null;
  66     private static RuntimeImpl         runtimeMBean = null;
  67     private static CompilationImpl     compileMBean = null;
  68     private static OperatingSystemImpl osMBean = null;
  69 


  87         }
  88         return threadMBean;
  89     }
  90 
  91     public static synchronized RuntimeMXBean getRuntimeMXBean() {
  92         if (runtimeMBean == null) {
  93             runtimeMBean = new RuntimeImpl(jvm);
  94         }
  95         return runtimeMBean;
  96     }
  97 
  98     public static synchronized CompilationMXBean getCompilationMXBean() {
  99         if (compileMBean == null && jvm.getCompilerName() != null) {
 100             compileMBean = new CompilationImpl(jvm);
 101         }
 102         return compileMBean;
 103     }
 104 
 105     public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
 106         if (osMBean == null) {
 107             osMBean = (OperatingSystemImpl)
 108                           OSMBeanFactory.getOperatingSystemMXBean(jvm);
 109         }
 110         return osMBean;
 111     }
 112 
 113     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
 114         MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
 115         List<MemoryPoolMXBean> list = new ArrayList<>(pools.length);
 116         for (MemoryPoolMXBean p : pools) {
 117             list.add(p);
 118         }
 119         return list;
 120     }
 121 
 122     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
 123         MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
 124         List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length);
 125         for (MemoryManagerMXBean m : mgrs) {
 126             result.add(m);
 127         }
 128         return result;




  29 
  30 import javax.management.DynamicMBean;
  31 import javax.management.InstanceAlreadyExistsException;
  32 import javax.management.InstanceNotFoundException;
  33 import javax.management.MBeanServer;
  34 import javax.management.MBeanRegistrationException;
  35 import javax.management.NotCompliantMBeanException;
  36 import javax.management.ObjectName;
  37 import javax.management.RuntimeOperationsException;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedActionException;
  40 import java.security.PrivilegedExceptionAction;
  41 
  42 import sun.util.logging.LoggingSupport;
  43 
  44 import java.util.ArrayList;
  45 import java.util.Collections;
  46 import java.util.HashMap;
  47 import java.util.List;
  48 import com.sun.management.DiagnosticCommandMBean;

  49 import com.sun.management.HotSpotDiagnosticMXBean;
  50 
  51 import static java.lang.management.ManagementFactory.*;
  52 
  53 /**
  54  * ManagementFactoryHelper provides static factory methods to create
  55  * instances of the management interface.
  56  */
  57 public class ManagementFactoryHelper {
  58     private ManagementFactoryHelper() {};
  59 
  60     private static VMManagement jvm;
  61 
  62     private static ClassLoadingImpl    classMBean = null;
  63     private static MemoryImpl          memoryMBean = null;
  64     private static ThreadImpl          threadMBean = null;
  65     private static RuntimeImpl         runtimeMBean = null;
  66     private static CompilationImpl     compileMBean = null;
  67     private static OperatingSystemImpl osMBean = null;
  68 


  86         }
  87         return threadMBean;
  88     }
  89 
  90     public static synchronized RuntimeMXBean getRuntimeMXBean() {
  91         if (runtimeMBean == null) {
  92             runtimeMBean = new RuntimeImpl(jvm);
  93         }
  94         return runtimeMBean;
  95     }
  96 
  97     public static synchronized CompilationMXBean getCompilationMXBean() {
  98         if (compileMBean == null && jvm.getCompilerName() != null) {
  99             compileMBean = new CompilationImpl(jvm);
 100         }
 101         return compileMBean;
 102     }
 103 
 104     public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() {
 105         if (osMBean == null) {
 106             osMBean = new OperatingSystemImpl(jvm);

 107         }
 108         return osMBean;
 109     }
 110 
 111     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
 112         MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
 113         List<MemoryPoolMXBean> list = new ArrayList<>(pools.length);
 114         for (MemoryPoolMXBean p : pools) {
 115             list.add(p);
 116         }
 117         return list;
 118     }
 119 
 120     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
 121         MemoryManagerMXBean[]  mgrs = MemoryImpl.getMemoryManagers();
 122         List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length);
 123         for (MemoryManagerMXBean m : mgrs) {
 124             result.add(m);
 125         }
 126         return result;