mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

lutoff
15.27.2008 c9039604a72310fbd1a471f735a96b97e1fc8b0a
Fix for issue #2806 (Use of com.sun.management.OperatingSystemMXBean breaks AIX)

Instead of using "com.sun.management.OperatingSystemMXBean", we now
introspect in MXBean in order to see if it's a Sun implementation.
1 files modified
44 ■■■■ changed files
opends/src/server/org/opends/server/util/RuntimeInformation.java 44 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/RuntimeInformation.java
@@ -35,6 +35,10 @@
 import java.lang.management.RuntimeMXBean;
 import java.lang.management.ManagementFactory;
 import java.util.List;
import javax.management.MBeanServer;
import javax.management.ObjectName;
 import com.sleepycat.je.JEVersion;
@@ -154,11 +158,29 @@
    *
    * @return Bytes of physical memory of the hardware we are running on.
    */
   private static long getPhysicalMemorySize() {
     com.sun.management.OperatingSystemMXBean mxbean =
             (com.sun.management.OperatingSystemMXBean)
             ManagementFactory.getOperatingSystemMXBean();
     return mxbean.getTotalPhysicalMemorySize();
  private static long getPhysicalMemorySize()
  {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try
    {
      // Assuming the RuntimeMXBean has been registered in mbs
      ObjectName oname = new ObjectName(
          ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
      // Check if this MXBean contains Sun's extension
      if (mbs.isInstanceOf(oname, "com.sun.management.OperatingSystemMXBean")) {
          // Get platform-specific attribute "TotalPhysicalMemorySize"
          Long l = (Long) mbs.getAttribute(oname, "TotalPhysicalMemorySize");
          return l ;
      }
      else
      {
        return -1;
      }
    }
    catch (Exception e)
    {
      return -1;
    }
   }
   /**
@@ -215,9 +237,17 @@
    logError(NOTE_JVM_INFO.get(System.getProperty("java.vm.version"),
                               System.getProperty("java.vm.vendor"),
                               getArch(),Runtime.getRuntime().maxMemory()));
    Long physicalMemorySize = getPhysicalMemorySize();
    if (physicalMemorySize != -1)
    {
    logError(NOTE_JVM_HOST.get(getHostName(),getOSInfo(),
                               getPhysicalMemorySize(),
                               Runtime.getRuntime().availableProcessors()));
          physicalMemorySize, Runtime.getRuntime().availableProcessors()));
    }
    else
    {
      logError(NOTE_JVM_HOST_WITH_UNKNOWN_PHYSICAL_MEM.get(getHostName(),
          getOSInfo(), Runtime.getRuntime().availableProcessors()));
    }
    logError(NOTE_JVM_ARGS.get(getInputArguments()));
   }
 }