Package wt.jmx.core

Class MBeanUtilities

java.lang.Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Value of THREAD_MBEAN.isCurrentThreadCpuTimeSupported().
    static final boolean
    Value of THREAD_MBEAN.isThreadCpuTimeSupported().
    Platform OperatingSystemMXBean (result of ManagementFactory.getOperatingSystemMXBean())

    Supported API: true
    static final RuntimeMXBean
    Platform RuntimeMXBean (result of ManagementFactory.getRuntimeMXBean())

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

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

    Supported API: true
  • Method Summary

    Modifier and Type
    Method
    Description
    static MBeanInfo
    fixOpenMBeanAttrInfo(MBeanInfo origMBeanInfo, Map<String,? extends 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
    Returns the available number of processors.
    static long[]
    Return ids of threads which are currently deadlocked or null if there are currently no deadlocked threads.
    static String[]
    Get full stack trace (from THREAD_MBEAN) as an array of Strings.
    static int
    getInitialHashCapacity(int initialElementCount, float loadFactor)
    Compute actual initial size of hash map/set needed to ensure no rehashing is done for the specified initial element count

    Supported API: true
    static long
    getMilliTimeFromNanoTime(long nanoTime)
    Deprecated.
    static long
    getNanoTimeFromMilliTime(long milliTime)
    Deprecated.
    static long
    Get a (per instance of this class) unique sequence number specifically for use in giving ids to notifications.
    static long
    Returns CPU time consumed by process since startup in nanosecond precision (but not necessarily nanosecond accuracy).
    static CompositeData[]
    Sorts the given TabularData's CompositeData by field specified as TabularData's indexing keys and returns the CompositeData objects as an array.
    static long
    getThreadAllocatedBytes(long threadId)
    Where possible returns the estimated number of bytes allocated by the given thread.
    static long[]
    getThreadAllocatedBytes(long[] threadIds)
    Where possible returns the estimated number of bytes allocated by each of the specified threads.
    static long[]
    getThreadCpuTimes(long[] threadIds)
    Returns CPU times for each of the specified threads.
    static String[]
    Gets full single thread info (including stack trace) as a String array

    Supported API: true
    static String[]
    getThreadInfoAsStringArray(long threadId, Thread thread)
    Gets full single thread info (including stack trace) as a String array; if 'thread' is non-null it is used to provide additional information

    Supported API: true
    static String[]
    Gets full single thread info (including stack trace) as a String array

    Supported API: true
    static long[]
    getThreadUserTimes(long[] threadIds)
    Returns user times for each of the specified threads.
    static boolean
    Encapsulates calls to THREAD_MBEAN.isThreadCpuTimeEnabled().
    static <K, V> HashMap<K,V>
    newHashMap(int initialElementCount, float loadFactor)
    Produces a HashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing

    Supported API: true
    static <T> HashSet<T>
    newHashSet(int initialElementCount, float loadFactor)
    Produces a HashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing

    Supported API: true
    static <K, V> LinkedHashMap<K,V>
    newLinkedHashMap(int initialElementCount, float loadFactor)
    Produces a LinkedHashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing

    Supported API: true
    static <T> HashSet<T>
    newLinkedHashSet(int initialElementCount, float loadFactor)
    Produces a LinkedHashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing

    Supported API: true
    newTabularDataSupport(TabularType tabularType, int initialElementCount, float loadFactor)
    Produces TabularDataSupport object of an appropriate actual initial size to hold initialElementCount elements without rehashing

    Supported API: true
    static String
    Render as with Timestamp.toString() plus 4 digit RFC 822 time zone specification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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.getRuntimeMXBean())

      Supported API: true
    • OS_MBEAN

      public static final OperatingSystemMXBean OS_MBEAN
      Platform OperatingSystemMXBean (result of ManagementFactory.getOperatingSystemMXBean())

      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 Details

    • getNotificationSequenceNumber

      public static 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
    • getDeadlockedThreadIds

      public static long[] getDeadlockedThreadIds()
      Return ids of threads which are currently deadlocked or null if there are currently no deadlocked threads.

      Supported API: true
    • getFullStackTraceAsStringArray

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

      Supported API: true
    • getThreadAllocatedBytes

      public static long getThreadAllocatedBytes(long threadId)
      Where possible returns the estimated number of bytes allocated by the given thread. This functionality is currently specific to the Oracle HotSpot JVM and Java 6 Update 25 or higher. Where this is not possible, this method returns -1.

      Supported API: true
    • getThreadAllocatedBytes

      public static long[] getThreadAllocatedBytes(long[] threadIds)
      Where possible returns the estimated number of bytes allocated by each of the specified threads. This functionality is currently specific to the Oracle HotSpot JVM and Java 6 Update 25 or higher. Where this is not possible, this method returns null.

      Supported API: true
    • getThreadCpuTimes

      public static long[] getThreadCpuTimes(long[] threadIds)
      Returns CPU times for each of the specified threads. This method does not check if thread CPU time monitoring is supported and enabled, that is the caller's responsibility in this case.

      Supported API: true
    • getThreadUserTimes

      public static long[] getThreadUserTimes(long[] threadIds)
      Returns user times for each of the specified threads. This method does not check if thread CPU time monitoring is supported and enabled, that is the caller's responsibility in this case.

      Supported API: true
    • getThreadInfoAsStringArray

      public static String[] getThreadInfoAsStringArray(Thread thread)
      Gets full single thread info (including stack trace) as a String array

      Supported API: true
    • getThreadInfoAsStringArray

      public static String[] getThreadInfoAsStringArray(long threadId)
      Gets full single thread info (including stack trace) as a String array

      Supported API: true
    • getThreadInfoAsStringArray

      public static String[] getThreadInfoAsStringArray(long threadId, Thread thread)
      Gets full single thread info (including stack trace) as a String array; if 'thread' is non-null it is used to provide additional information

      Supported API: true
    • renderAsTimestampPlusTimeZone

      public static String renderAsTimestampPlusTimeZone(Date timestamp)
      Render as with Timestamp.toString() plus 4 digit RFC 822 time zone specification.

      Supported API: true
    • formatMessage

      public static 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

      @Deprecated public static long getMilliTimeFromNanoTime(long nanoTime)
      Deprecated.
      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.

      This method is now deprecated because any manual or automatic change to the system clock during application execution will alter the offset between these timers and thus introduce error in the conversion.

      Supported API: true

    • getNanoTimeFromMilliTime

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

      This method is now deprecated because any manual or automatic change to the system clock during application execution will alter the offset between these timers and thus introduce error in the conversion.

      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,? extends 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

    • newHashMap

      public static <K, V> HashMap<K,V> newHashMap(int initialElementCount, float loadFactor)
      Produces a HashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing

      Supported API: true
    • newLinkedHashMap

      public static <K, V> LinkedHashMap<K,V> newLinkedHashMap(int initialElementCount, float loadFactor)
      Produces a LinkedHashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing

      Supported API: true
    • newHashSet

      public static <T> HashSet<T> newHashSet(int initialElementCount, float loadFactor)
      Produces a HashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing

      Supported API: true
    • newLinkedHashSet

      public static <T> HashSet<T> newLinkedHashSet(int initialElementCount, float loadFactor)
      Produces a LinkedHashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing

      Supported API: true
    • newTabularDataSupport

      public static TabularDataSupport newTabularDataSupport(TabularType tabularType, int initialElementCount, float loadFactor)
      Produces TabularDataSupport object of an appropriate actual initial size to hold initialElementCount elements without rehashing

      Supported API: true
    • getInitialHashCapacity

      public static int getInitialHashCapacity(int initialElementCount, float loadFactor)
      Compute actual initial size of hash map/set needed to ensure no rehashing is done for the specified initial element count

      Supported API: true