Class ExtendedOperatingSystemMXBeanImpl
- All Implemented Interfaces:
OperatingSystemMXBean
,OperatingSystemMXBean
,OperatingSystemMXBean
,PlatformManagedObject
,NotificationBroadcaster
,NotificationEmitter
- Direct Known Subclasses:
UnixExtendedOperatingSystem
OperatingSystemMXBean
.- Since:
- 1.7.1
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Adds a listener to this MBean.long
Returns the amount of virtual memory used by the process in bytes.final double
Returns the "recent cpu usage" for the operating environment.long
Returns the amount of free memory in bytes.final long
Returns the amount of free swap space in bytes.final String
Retrieve hardware modelSingleton accessor method.final MBeanNotificationInfo[]
Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.final double
Returns the recent CPU usage for the Java Virtual Machine process.final long
Returns total amount of time the process has been scheduled or executed so far in both kernel and user modes.final long
Deprecated, for removal: This API element is subject to removal in a future version.final int
Returns the collective capacity of the virtual processors in the partition the VM is running in.final long
Returns the amount of physical memory being used by the process in bytes.final long
Returns the amount of private memory used by the process in bytes.final long
Deprecated, for removal: This API element is subject to removal in a future version.long
Returns the total amount of memory in bytes.final long
Deprecated, for removal: This API element is subject to removal in a future version.final long
Returns the total amount of swap space in bytes.final boolean
Identify whether the underlying hardware is being emulatedboolean
isProcessRunning
(long pid) Indicates if the specified process is runningfinal void
Removes a listener from this MBean.final void
removeNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Removes a listener from this MBean.final MemoryUsage
Instantiates and returns an instance ofMemoryUsage
object that represents the current snapshot of Memory usage statistics.final MemoryUsage
retrieveMemoryUsage
(MemoryUsage memoryUsageObj) Returns an updatedMemoryUsage
object that represents the current snapshot of Memory usage statistics.final ProcessorUsage[]
Instantiates and returns an array ofProcessorUsage
objects that represent the current snapshot of individual Processor usage times.final ProcessorUsage[]
retrieveProcessorUsage
(ProcessorUsage[] procUsageArr) Returns an updated array ofProcessorUsage
objects that represent the current snapshot of individual Processor usage times.final ProcessorUsage
Instantiate and return a newProcessorUsage
object that represents the current snapshot of Processor usage statistics.final ProcessorUsage
retrieveTotalProcessorUsage
(ProcessorUsage procUsageObj) Returns an updatedProcessorUsage
object that represents the current snapshot of Processor usage statistics.final void
sendNotification
(Notification notification) Send notifications to registered listeners.Methods declared in class com.ibm.java.lang.management.internal.OperatingSystemMXBeanImpl
getArch, getAvailableProcessors, getName, getObjectName, getSystemLoadAverage, getVersion
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface com.sun.management.OperatingSystemMXBean
getFreePhysicalMemorySize, getSystemCpuLoad, getTotalPhysicalMemorySize
Methods declared in interface java.lang.management.OperatingSystemMXBean
getArch, getAvailableProcessors, getName, getSystemLoadAverage, getVersion
Methods declared in interface java.lang.management.PlatformManagedObject
getObjectName
-
Method Details
-
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. All values betweens 0.0 and 1.0 are possible depending of the activities going on. If the recent cpu usage is not available, the method returns a negative value.- Specified by:
getCpuLoad
in interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- Returns:
- the total amount of memory in bytes.
-
getFreeMemorySize
public long getFreeMemorySize()Returns the amount of free memory in bytes.- Specified by:
getFreeMemorySize
in interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- Specified by:
getFreeSwapSpaceSize
in interfaceOperatingSystemMXBean
- Returns:
- the amount of free swap space in bytes.
-
getHardwareModel
Retrieve hardware model- Specified by:
getHardwareModel
in interfaceOperatingSystemMXBean
- 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 returnsCpuLoadCalculationConstants
.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 fromCpuLoadCalculationConstants
.- Specified by:
getProcessCpuLoad
in interfaceOperatingSystemMXBean
- Specified by:
getProcessCpuLoad
in interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- Specified by:
getProcessCpuTime
in interfaceOperatingSystemMXBean
- Returns:
- process CPU time.
-
getProcessCpuTimeByNS
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated. Use getProcessCpuTime()- Specified by:
getProcessCpuTimeByNS
in interfaceOperatingSystemMXBean
-
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 interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- 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 interfaceOperatingSystemMXBean
- Specified by:
getCommittedVirtualMemorySize
in interfaceOperatingSystemMXBean
- Returns:
- amount of virtual memory used by the process in bytes.
-
getProcessVirtualMemorySize
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated. Use getCommittedVirtualMemorySize()- Specified by:
getProcessVirtualMemorySize
in interfaceOperatingSystemMXBean
-
getTotalPhysicalMemory
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated: use getTotalMemorySize()- Specified by:
getTotalPhysicalMemory
in interfaceOperatingSystemMXBean
- Returns:
- the total available physical memory on the system in bytes.
-
getTotalSwapSpaceSize
public final long getTotalSwapSpaceSize()Returns the total amount of swap space in bytes.- Specified by:
getTotalSwapSpaceSize
in interfaceOperatingSystemMXBean
- Specified by:
getTotalSwapSpaceSize
in interfaceOperatingSystemMXBean
- Returns:
- the total amount of swap space in bytes.
-
isHardwareEmulated
Identify whether the underlying hardware is being emulated- Specified by:
isHardwareEmulated
in interfaceOperatingSystemMXBean
- 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
Instantiates and returns an instance ofMemoryUsage
object that represents the current snapshot of Memory usage statistics.- Specified by:
retrieveMemoryUsage
in interfaceOperatingSystemMXBean
- 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 updatedMemoryUsage
object that represents the current snapshot of Memory usage statistics.- Specified by:
retrieveMemoryUsage
in interfaceOperatingSystemMXBean
- Parameters:
memoryUsageObj
- User providedMemoryUsage
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
Instantiates and returns an array ofProcessorUsage
objects that represent the current snapshot of individual Processor usage times.- Specified by:
retrieveProcessorUsage
in interfaceOperatingSystemMXBean
- 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 ofProcessorUsage
objects that represent the current snapshot of individual Processor usage times.- Specified by:
retrieveProcessorUsage
in interfaceOperatingSystemMXBean
- Parameters:
procUsageArr
- User provided array ofProcessorUsage
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
Instantiate and return a newProcessorUsage
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 interfaceOperatingSystemMXBean
- 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 updatedProcessorUsage
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 interfaceOperatingSystemMXBean
- Parameters:
procUsageObj
- User providedProcessorUsage
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
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 interfaceNotificationBroadcaster
- 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 interfaceOperatingSystemMXBean
- Parameters:
pid
- Operating system process ID- Returns:
- True if the specified process exists
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException Adds a listener to this MBean.- Specified by:
addNotificationListener
in interfaceNotificationBroadcaster
- 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 interfaceNotificationBroadcaster
- 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
, andhandback
parameters. If there is more than one such listener, only one is removed.The
filter
andhandback
parameters may be null if and only if they are null in a listener to be removed.- Specified by:
removeNotificationListener
in interfaceNotificationEmitter
- 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
Send notifications to registered listeners.- Parameters:
notification
- a notification to be sent
-