wt.jmx.core
Class MBeanUtilities

java.lang.Object
  extended by wt.jmx.core.MBeanUtilities

public final class MBeanUtilities
extends Object

Collection of various utilities used in conjunction with implementation and use of JMX MBeans.

Supported API: true

Extendable: false


Field Summary
static boolean CURRENT_THREAD_CPU_TIME_SUPPORTED
          Value of THREAD_MBEAN.isCurrentThreadCpuTimeSupported().
static boolean NON_CURRENT_THREAD_CPU_TIME_SUPPORTED
          Value of THREAD_MBEAN.isThreadCpuTimeSupported().
static RuntimeMXBean RUNTIME_MBEAN
          Platform RuntimeMXBean (result of ManagementFactory.getRuntime())

Supported API: true
static boolean THREAD_CONTENTION_MONITORING_SUPPORTED
          Value of THREAD_MBEAN.isThreadContentionMonitoringSupported().
static ThreadMXBean THREAD_MBEAN
          Platform ThreadMXBean (result of ManagementFactory.getThreadMXBean())

Supported API: true
static long VM_START_TIME
          Java virtual machine start time (result of RUNTIME_MBEAN.getStartTime())

Supported API: true
 
Method Summary
static MBeanInfo fixOpenMBeanAttrInfo(MBeanInfo origMBeanInfo, Map<String,OpenType> attrNameToTypeMap)
          Returns updated version of the MBeanInfo provided wherein the MBeanAttributeInfo for each attribute named in the given map is replaced by an OpenMBeanAttributeInfo that is identical except that corresponding OpenType from the map is specified as the return type.
static String formatMessage(String messageFormat, Object... formatArgs)
          Localized (and simplified) replacement for WTMessage to avoid this dependency in lower-level MBean code.
static int getAvailableProcessors()
          Returns the available number of processors.
static String[] getFullStackTraceAsStringArray()
          Get full stack trace (from THREAD_MBEAN) as an array of Strings.
static long getMilliTimeFromNanoTime(long nanoTime)
          Convert from a System.nanoTime() results to an approximate System.currentTimeMillis() result.
static long getNanoTimeFromMilliTime(long milliTime)
          Inverse operation of getMilliTimeFromNanoTime().
static long getNotificationSequenceNumber()
          Get a (per instance of this class) unique sequence number specifically for use in giving ids to notifications.
static long getProcessCpuTime()
          Returns CPU time consumed by process since startup in nanosecond precision (but not necessarily nanosecond accuracy).
static CompositeData[] getSortedData(TabularData tabularData)
          Sorts the given TabularData's CompositeData by field specified as TabularData's indexing keys and returns the CompositeData objects as an array.
static boolean isThreadCpuTimeEnabled()
          Encapsulates calls to THREAD_MBEAN.isThreadCpuTimeEnabled().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THREAD_MBEAN

public static final ThreadMXBean THREAD_MBEAN
Platform ThreadMXBean (result of ManagementFactory.getThreadMXBean())

Supported API: true


RUNTIME_MBEAN

public static final RuntimeMXBean RUNTIME_MBEAN
Platform RuntimeMXBean (result of ManagementFactory.getRuntime())

Supported API: true


VM_START_TIME

public static final long VM_START_TIME
Java virtual machine start time (result of RUNTIME_MBEAN.getStartTime())

Supported API: true


CURRENT_THREAD_CPU_TIME_SUPPORTED

public static final boolean CURRENT_THREAD_CPU_TIME_SUPPORTED
Value of THREAD_MBEAN.isCurrentThreadCpuTimeSupported().

Supported API: true


NON_CURRENT_THREAD_CPU_TIME_SUPPORTED

public static final boolean NON_CURRENT_THREAD_CPU_TIME_SUPPORTED
Value of THREAD_MBEAN.isThreadCpuTimeSupported().

Supported API: true


THREAD_CONTENTION_MONITORING_SUPPORTED

public static final boolean THREAD_CONTENTION_MONITORING_SUPPORTED
Value of THREAD_MBEAN.isThreadContentionMonitoringSupported().

Supported API: true

Method Detail

getNotificationSequenceNumber

public static final long getNotificationSequenceNumber()
Get a (per instance of this class) unique sequence number specifically for use in giving ids to notifications.

Supported API: true


getProcessCpuTime

public static long getProcessCpuTime()
Returns CPU time consumed by process since startup in nanosecond precision (but not necessarily nanosecond accuracy).

Note that this method assumes that the ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME has an attribute named "ProcessCpuTime" containing this information, which is the case in Sun JVMs. If such an attribute is not found, then this method will simply return 0.

Supported API: true


getAvailableProcessors

public static int getAvailableProcessors()
Returns the available number of processors. This is essentially a shortcut for Runtime.getRuntime().availableProcessors().

Supported API: true


getFullStackTraceAsStringArray

public static String[] getFullStackTraceAsStringArray()
Get full stack trace (from THREAD_MBEAN) as an array of Strings.

Supported API: true


formatMessage

public static final String formatMessage(String messageFormat,
                                         Object... formatArgs)
Localized (and simplified) replacement for WTMessage to avoid this dependency in lower-level MBean code. This routine should be used instead of directly using MessageFormat to provide easier handling of quote characters for localizers.

Supported API: true


getMilliTimeFromNanoTime

public static long getMilliTimeFromNanoTime(long nanoTime)
Convert from a System.nanoTime() results to an approximate System.currentTimeMillis() result. Note that this is not simply the input divided by 1000000L (do that yourself as needed to convert from an elapsed nanosecond to millisecond time). Rather this handles the offset between System.nanoTime() and System.currentTimeMillis() results so that the result of this routine can be used in constructing Dates, Timestamps, etc.

Supported API: true


getNanoTimeFromMilliTime

public static long getNanoTimeFromMilliTime(long milliTime)
Inverse operation of getMilliTimeFromNanoTime().

Supported API: true


getSortedData

public static CompositeData[] getSortedData(TabularData tabularData)
Sorts the given TabularData's CompositeData by field specified as TabularData's indexing keys and returns the CompositeData objects as an array.

The CompositeData within a TabularData are naturally in hash order, so this utility is necessary when a human-meaningful ordering is desired.

Supported API: true


fixOpenMBeanAttrInfo

public static MBeanInfo fixOpenMBeanAttrInfo(MBeanInfo origMBeanInfo,
                                             Map<String,OpenType> attrNameToTypeMap)
Returns updated version of the MBeanInfo provided wherein the MBeanAttributeInfo for each attribute named in the given map is replaced by an OpenMBeanAttributeInfo that is identical except that corresponding OpenType from the map is specified as the return type.

This is the correct thing to do when for attributes returning TabularData or CompositeData in that this allows JMX applications to programmatically determine the precise data type that will be returned without / prior to fetching a value. It seems that most JMX consoles do not require this level of precision, however, so this is not strictly necessary.

Supported API: true

Parameters:
origMBeanInfo - Original MBeanInfo object
attrNameToTypeMap - Map from attribute names to corresponding OpenTypes
Returns:
Augmented/updated MBeanInfo

isThreadCpuTimeEnabled

public static boolean isThreadCpuTimeEnabled()
Encapsulates calls to THREAD_MBEAN.isThreadCpuTimeEnabled(). This allows us to work around issues in some JVMs wherein an UnsupportedOperationException is thrown even though isCurrentThreadCpuTimeSupported() returns true! This is done by returning catching UnsupportedOperationExceptions and returning false in such cases.

One should check CURRENT_THREAD_CPU_TIME_SUPPORTED and/or NON_CURRENT_THREAD_CPU_TIME_SUPPORTED prior to calling this method despite its internal workaround to save the overhead of unnecessary exception throws.

Supported API: true