Class ExtendedOperatingSystemMXBeanImpl

java.lang.Object
com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl
All Implemented Interfaces:
OperatingSystemMXBean, OperatingSystemMXBean, OperatingSystemMXBean, PlatformManagedObject, NotificationBroadcaster, NotificationEmitter
Direct Known Subclasses:
UnixExtendedOperatingSystem

public class ExtendedOperatingSystemMXBeanImpl extends Object implements OperatingSystemMXBean
Runtime type for OperatingSystemMXBean.
Since:
1.7.1
  • Method Details

    • getInstance

      public static ExtendedOperatingSystemMXBeanImpl getInstance()
      Singleton accessor method.
      Returns:
      the ExtendedOperatingSystemMXBeanImpl singleton.
    • getCpuLoad

      public final double getCpuLoad()
      Returns the "recent CPU usage" for the operating environment. This value is a double in the [0.0,1.0] interval. A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed. The recent period of observation is implementation-specific, and typically relates to the duration since the last call made to this method, or OperatingSystemMXBean.getSystemCpuLoad(). For the very first invocation, the recent period of observation is undefined. All values between 0.0 and 1.0 are possible dependent on the activities going on. If the recent CPU usage is not available, the method returns a negative value.
      Specified by:
      getCpuLoad in interface OperatingSystemMXBean
      Returns:
      the "recent cpu usage" for the whole operating environment; a negative value if not available.
    • getTotalMemorySize

      public long getTotalMemorySize()
      Returns the total amount of memory in bytes.
      Specified by:
      getTotalMemorySize in interface OperatingSystemMXBean
      Returns:
      the total amount of memory in bytes.
    • getFreeMemorySize

      public long getFreeMemorySize()
      Returns the amount of free memory in bytes.
      Specified by:
      getFreeMemorySize in interface OperatingSystemMXBean
      Returns:
      the amount of free memory in bytes.
    • getFreeSwapSpaceSize

      public final long getFreeSwapSpaceSize()
      Returns the amount of free swap space in bytes.
      Specified by:
      getFreeSwapSpaceSize in interface OperatingSystemMXBean
      Specified by:
      getFreeSwapSpaceSize in interface OperatingSystemMXBean
      Returns:
      the amount of free swap space in bytes.
    • getHardwareModel

      public final String getHardwareModel() throws UnsupportedOperationException
      Retrieve hardware model
      Specified by:
      getHardwareModel in interface OperatingSystemMXBean
      Returns:
      String containing the hardware model. NULL in case of an error.
      Throws:
      UnsupportedOperationException - if the operation is not implemented on this platform. UnsupportedOperationException will also be thrown if the operation is implemented but it cannot be performed because the system does not satisfy all the requirements, for example, an OS service is not installed.
    • getProcessCpuLoad

      public final double getProcessCpuLoad()
      Returns the recent CPU usage for the Java Virtual Machine process. This value is a double in the [0.0,1.0] interval. A value of 0.0 means that none of the CPUs were running threads from the JVM process during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running threads from the JVM 100% of the time during the recent period of time observed. Threads from the JVM include application threads as well as JVM internal threads. All values between 0.0 and 1.0 are possible. The first call to the method always returns CpuLoadCalculationConstants.ERROR_VALUE (-1.0), which marks the starting point. If the Java Virtual Machine's recent CPU usage is not available, the method returns a negative error code from CpuLoadCalculationConstants.
      Specified by:
      getProcessCpuLoad in interface OperatingSystemMXBean
      Specified by:
      getProcessCpuLoad in interface OperatingSystemMXBean
      Returns:
      A value between 0 and 1.0, or a negative error code from CpuLoadCalculationConstants in case of an error. On the first call to the API, CpuLoadCalculationConstants.ERROR_VALUE (-1.0) shall be returned.
      See Also:
    • getProcessCpuTime

      public final long getProcessCpuTime()
      Returns total amount of time the process has been scheduled or executed so far in both kernel and user modes. Returns -1 if the value is unavailable on this platform or in the case of an error. Note that as of Java 8 SR5 the returned value is in 1 ns units, unless the system property com.ibm.lang.management.OperatingSystemMXBean.isCpuTime100ns is set to "true".
      Specified by:
      getProcessCpuTime in interface OperatingSystemMXBean
      Specified by:
      getProcessCpuTime in interface OperatingSystemMXBean
      Returns:
      process CPU time.
    • getProcessingCapacity

      public final int getProcessingCapacity()
      Returns the collective capacity of the virtual processors in the partition the VM is running in. The value returned is in units of 1% of a physical processor's capacity, so a value of 100 is equal to 1 physical processor. In environments without such partitioning support, this call will return getAvailableProcessors() * 100.
      Specified by:
      getProcessingCapacity in interface OperatingSystemMXBean
      Returns:
      the collective capacity of the virtual processors available to the VM.
    • getProcessPhysicalMemorySize

      public final long getProcessPhysicalMemorySize()
      Returns the amount of physical memory being used by the process in bytes. Returns -1 if the value is unavailable on this platform or in the case of an error.
      • This information is not available on the AIX and z/OS platforms.
      Specified by:
      getProcessPhysicalMemorySize in interface OperatingSystemMXBean
      Returns:
      amount of physical memory being used by the process in bytes.
    • getProcessPrivateMemorySize

      public final long getProcessPrivateMemorySize()
      Returns the amount of private memory used by the process in bytes. Returns -1 if the value is unavailable on this platform or in the case of an error.
      • This information is not available on the z/OS platform.
      Specified by:
      getProcessPrivateMemorySize in interface OperatingSystemMXBean
      Returns:
      amount of private memory used by the process in bytes.
    • getCommittedVirtualMemorySize

      public long getCommittedVirtualMemorySize()
      Returns the amount of virtual memory used by the process in bytes. Returns -1 if the value is unavailable on this platform or in the case of an error.
      • This information is not available on the z/OS platform.
      Specified by:
      getCommittedVirtualMemorySize in interface OperatingSystemMXBean
      Specified by:
      getCommittedVirtualMemorySize in interface OperatingSystemMXBean
      Returns:
      amount of virtual memory used by the process in bytes.
    • getTotalSwapSpaceSize

      public final long getTotalSwapSpaceSize()
      Returns the total amount of swap space in bytes.
      Specified by:
      getTotalSwapSpaceSize in interface OperatingSystemMXBean
      Specified by:
      getTotalSwapSpaceSize in interface OperatingSystemMXBean
      Returns:
      the total amount of swap space in bytes.
    • isHardwareEmulated

      public final boolean isHardwareEmulated() throws UnsupportedOperationException
      Identify whether the underlying hardware is being emulated
      Specified by:
      isHardwareEmulated in interface OperatingSystemMXBean
      Returns:
      True if it is possible to identify that the hardware is being emulated. False otherwise.
      Throws:
      UnsupportedOperationException - if the emulated status cannot be determined
    • retrieveMemoryUsage

      public final MemoryUsage retrieveMemoryUsage() throws MemoryUsageRetrievalException
      Instantiates and returns an instance of MemoryUsage object that represents the current snapshot of Memory usage statistics.
      Specified by:
      retrieveMemoryUsage in interface OperatingSystemMXBean
      Returns:
      The new MemoryUsage object.
      Throws:
      MemoryUsageRetrievalException - if it failed obtaining Memory usage statistics.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • retrieveMemoryUsage

      public final MemoryUsage retrieveMemoryUsage(MemoryUsage memoryUsageObj) throws NullPointerException, MemoryUsageRetrievalException
      Returns an updated MemoryUsage object that represents the current snapshot of Memory usage statistics.
      Specified by:
      retrieveMemoryUsage in interface OperatingSystemMXBean
      Parameters:
      memoryUsageObj - User provided MemoryUsage object.
      Returns:
      The updated MemoryUsage object.
      Throws:
      NullPointerException - if a null reference is passed as parameter.
      MemoryUsageRetrievalException - if it failed obtaining Memory usage statistics.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • retrieveProcessorUsage

      public final ProcessorUsage[] retrieveProcessorUsage() throws ProcessorUsageRetrievalException
      Instantiates and returns an array of ProcessorUsage objects that represent the current snapshot of individual Processor usage times.
      Specified by:
      retrieveProcessorUsage in interface OperatingSystemMXBean
      Returns:
      The new array of ProcessorUsage objects.
      Throws:
      ProcessorUsageRetrievalException - if it failed obtaining Processor usage statistics.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • retrieveProcessorUsage

      public final ProcessorUsage[] retrieveProcessorUsage(ProcessorUsage[] procUsageArr) throws NullPointerException, ProcessorUsageRetrievalException, IllegalArgumentException
      Returns an updated array of ProcessorUsage objects that represent the current snapshot of individual Processor usage times.
      Specified by:
      retrieveProcessorUsage in interface OperatingSystemMXBean
      Parameters:
      procUsageArr - User provided array of ProcessorUsage objects.
      Returns:
      The updated array of ProcessorUsage objects.
      Throws:
      NullPointerException - if a null reference is passed as parameter.
      ProcessorUsageRetrievalException - if it failed obtaining Processor usage statistics.
      IllegalArgumentException - if array provided has insufficient entries and there are more Processors to report on.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • retrieveTotalProcessorUsage

      public final ProcessorUsage retrieveTotalProcessorUsage() throws ProcessorUsageRetrievalException
      Instantiate and return a new ProcessorUsage object that represents the current snapshot of Processor usage statistics. The snapshot is the aggregate of all Processors that are online at the time of sampling.
      Specified by:
      retrieveTotalProcessorUsage in interface OperatingSystemMXBean
      Returns:
      The new ProcessorUsage object.
      Throws:
      ProcessorUsageRetrievalException - if it failed obtaining Processor usage statistics.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • retrieveTotalProcessorUsage

      public final ProcessorUsage retrieveTotalProcessorUsage(ProcessorUsage procUsageObj) throws NullPointerException, ProcessorUsageRetrievalException
      Returns an updated ProcessorUsage object that represents the current snapshot of Processor usage statistics. The snapshot is the aggregate of all Processors that are online at the time of sampling.
      Specified by:
      retrieveTotalProcessorUsage in interface OperatingSystemMXBean
      Parameters:
      procUsageObj - User provided ProcessorUsage object.
      Returns:
      The updated ProcessorUsage object.
      Throws:
      NullPointerException - if a null reference is passed as parameter.
      ProcessorUsageRetrievalException - if it failed obtaining Processor usage statistics.

      In case of an exception, the handler code might use toString() on the exception code to obtain a description of the exception.

    • getNotificationInfo

      public final MBeanNotificationInfo[] getNotificationInfo()

      Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.

      It is not illegal for the MBean to send notifications not described in this array. However, some clients of the MBean server may depend on the array being complete for their correct functioning.

      Specified by:
      getNotificationInfo in interface NotificationBroadcaster
      Returns:
      the array of possible notifications.
    • isProcessRunning

      public boolean isProcessRunning(long pid)
      Description copied from interface: OperatingSystemMXBean
      Indicates if the specified process is running
      Specified by:
      isProcessRunning in interface OperatingSystemMXBean
      Parameters:
      pid - Operating system process ID
      Returns:
      True if the specified process exists
    • getArch

      public final String getArch()
      Returns a unique string identifier for the architecture of the underlying operating system. The identifier value is identical to that which would be obtained from a call to System.getProperty(java.lang.String) supplying the value "os.arch" for the key.
      Specified by:
      getArch in interface OperatingSystemMXBean
      Returns:
      the identifier for the operating system architecture.
      See Also:
    • getAvailableProcessors

      public final int getAvailableProcessors()
      Returns the number of processors that are available for the virtual machine to run on. The information returned from this method is identical to that which would be received from a call to Runtime.availableProcessors().
      Specified by:
      getAvailableProcessors in interface OperatingSystemMXBean
      Returns:
      the number of available processors.
    • getName

      public final String getName()
      Returns the name of the underlying operating system. The value is identical to that which would be obtained from a call to System.getProperty(java.lang.String) supplying the value "os.name" for the key.
      Specified by:
      getName in interface OperatingSystemMXBean
      Returns:
      the name of the operating system.
      See Also:
    • getObjectName

      public final ObjectName getObjectName()
      Returns an ObjectName instance representing the object name of this platform managed object.
      Specified by:
      getObjectName in interface PlatformManagedObject
      Returns:
      an ObjectName instance representing the object name of this platform managed object.
    • getSystemLoadAverage

      public final double getSystemLoadAverage()
      Returns a double value which holds the system load average calculated for the minute preceding the call, where system load average is taken to mean the following:

      the time-averaged value of the sum of the number of runnable entities running on the available processors and the number of runnable entities ready and queued to run on the available processors. The averaging technique adopted can vary depending on the underlying operating system.

      Specified by:
      getSystemLoadAverage in interface OperatingSystemMXBean
      Returns:
      normally, the system load average as a double. If the system load average is not obtainable (e.g. because the calculation may involve an unacceptable performance impact) then a negative value is returned.
    • getVersion

      public final String getVersion()
      Returns the version string for the underlying operating system. The value is identical to that which would be obtained from a call to System.getProperty(java.lang.String) supplying the value "os.version" for the key.
      Specified by:
      getVersion in interface OperatingSystemMXBean
      Returns:
      the version of the operating system.
      See Also:
    • addNotificationListener

      public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException
      Adds a listener to this MBean.
      Specified by:
      addNotificationListener in interface NotificationBroadcaster
      Parameters:
      listener - The listener object which will handle the notifications emitted by the broadcaster.
      filter - The filter object. If filter is null, no filtering will be performed before handling notifications.
      handback - An opaque object to be sent back to the listener when a notification is emitted. This object cannot be used by the Notification broadcaster object. It should be resent unchanged with the notification to the listener.
      Throws:
      IllegalArgumentException - Listener parameter is null.
      See Also:
    • removeNotificationListener

      public final void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
      Removes a listener from this MBean. If the listener has been registered with different handback objects or notification filters, all entries corresponding to the listener will be removed.
      Specified by:
      removeNotificationListener in interface NotificationBroadcaster
      Parameters:
      listener - A listener that was previously added to this MBean.
      Throws:
      ListenerNotFoundException - The listener is not registered with the MBean.
      See Also:
    • removeNotificationListener

      public final void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException

      Removes a listener from this MBean. The MBean must have a listener that exactly matches the given listener, filter, and handback parameters. If there is more than one such listener, only one is removed.

      The filter and handback parameters may be null if and only if they are null in a listener to be removed.

      Specified by:
      removeNotificationListener in interface NotificationEmitter
      Parameters:
      listener - A listener that was previously added to this MBean.
      filter - The filter that was specified when the listener was added.
      handback - The handback that was specified when the listener was added.
      Throws:
      ListenerNotFoundException - The listener is not registered with the MBean, or it is not registered with the given filter and handback.
    • sendNotification

      public final void sendNotification(Notification notification)
      Send notifications to registered listeners.
      Parameters:
      notification - a notification to be sent