private void initAndCheckEnvironment() throws Exception {
  Class<?> ibmOperatingSystemMxBeanClass=Class.forName(IBM_OPERATING_SYSTEM_MX_BEAN_CLASS);
  if (null != ibmOperatingSystemMxBeanClass) {
    Method getInstanceMethod=ibmOperatingSystemMxBeanClass.getDeclaredMethod("getInstance");
    getInstanceMethod.setAccessible(true);
    if (null != getInstanceMethod) {
      ibmOperatingSystemMxBeanInstance=getInstanceMethod.invoke(null);
    }
    if (null != ibmOperatingSystemMxBeanInstance) {
      committedVirtualMemorySizeMethod=getMethod(ibmOperatingSystemMxBeanClass,"getProcessVirtualMemorySize");
      Object result=getValueFromMethodInvocation(ibmOperatingSystemMxBeanInstance,committedVirtualMemorySizeMethod);
      if (!(result instanceof Number)) {
        throw new Exception("Result of getProcessVirtualMemorySize() method invocation is not a number. Result was: " + result);
      }
      freePhysicalMemorySizeMethod=getMethod(ibmOperatingSystemMxBeanClass,"getFreePhysicalMemorySize");
      result=getValueFromMethodInvocation(ibmOperatingSystemMxBeanInstance,freePhysicalMemorySizeMethod);
      if (!(result instanceof Number)) {
        throw new Exception("Result of getFreePhysicalMemorySize() method invocation is not a number. Result was: " + result);
      }
      processCpuTimeMethod=getMethod(ibmOperatingSystemMxBeanClass,"getProcessCpuTime");
      result=getValueFromMethodInvocation(ibmOperatingSystemMxBeanInstance,processCpuTimeMethod);
      if (!(result instanceof Number)) {
        throw new Exception("Result of getProcessCpuTime() method invocation is not a number. Result was: " + result);
      }
      totalPhysicalMemorySizeMethod=getMethod(ibmOperatingSystemMxBeanClass,"getTotalPhysicalMemory");
      result=getValueFromMethodInvocation(ibmOperatingSystemMxBeanInstance,totalPhysicalMemorySizeMethod);
      if (!(result instanceof Number)) {
        throw new Exception("Result of getTotalPhysicalMemory() method invocation is not a number. Result was: " + result);
      }
    }
  }
}

private void initAndCheckEnvironment ( ) throws Exception { Class < ? > ibmOperatingSystemMxBeanClass = Class . forName ( IBM_OPERATING_SYSTEM_MX_BEAN_CLASS ) ; if ( null != ibmOperatingSystemMxBeanClass ) { Method getInstanceMethod = ibmOperatingSystemMxBeanClass . getDeclaredMethod ( "getInstance" ) ; getInstanceMethod . setAccessible ( true ) ; if ( null != getInstanceMethod ) { ibmOperatingSystemMxBeanInstance = getInstanceMethod . invoke ( null ) ; } if ( null != ibmOperatingSystemMxBeanInstance ) { committedVirtualMemorySizeMethod = getMethod ( ibmOperatingSystemMxBeanClass , "getProcessVirtualMemorySize" ) ; Object result = getValueFromMethodInvocation ( ibmOperatingSystemMxBeanInstance , committedVirtualMemorySizeMethod ) ; if ( ! ( result instanceof Number ) ) { throw new Exception ( "Result of getProcessVirtualMemorySize() method invocation is not a number. Result was: " + result ) ; } freePhysicalMemorySizeMethod = getMethod ( ibmOperatingSystemMxBeanClass , "getFreePhysicalMemorySize" ) ; result = getValueFromMethodInvocation ( ibmOperatingSystemMxBeanInstance , freePhysicalMemorySizeMethod ) ; if ( ! ( result instanceof Number ) ) { throw new Exception ( "Result of getFreePhysicalMemorySize() method invocation is not a number. Result was: " + result ) ; } processCpuTimeMethod = getMethod ( ibmOperatingSystemMxBeanClass , "getProcessCpuTime" ) ; result = getValueFromMethodInvocation ( ibmOperatingSystemMxBeanInstance , processCpuTimeMethod ) ; if ( ! ( result instanceof Number ) ) { throw new Exception ( "Result of getProcessCpuTime() method invocation is not a number. Result was: " + result ) ; } totalPhysicalMemorySizeMethod = getMethod ( ibmOperatingSystemMxBeanClass , "getTotalPhysicalMemory" ) ; result = getValueFromMethodInvocation ( ibmOperatingSystemMxBeanInstance , totalPhysicalMemorySizeMethod ) ; if ( ! ( result instanceof Number ) ) { throw new Exception ( "Result of getTotalPhysicalMemory() method invocation is not a number. Result was: " + result ) ; } } } }
initializes the class and checks if every method needed to be accessed with reflection is available and is returning the correct value .
