public class ManagementUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static boolean |
VERBOSE_MODE
System property setting used to decide if non-fatal exceptions should be
written out to console.
|
Constructor and Description |
---|
ManagementUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
convertFromCompositeData(javax.management.openmbean.CompositeData data,
java.lang.Class<T> realClass)
Return a new instance of type
T from the supplied
CompositeData object whose type maps to T . |
static <T> T |
convertFromOpenType(java.lang.Object data,
java.lang.Class<?> openClass,
java.lang.Class<T> realClass)
Receive data of the type specified in
openClass and return
it in an instance of the type specified in realClass . |
static java.util.List<java.lang.String> |
convertStringArrayToList(java.lang.String[] data)
Convenience method to converts an array of
String to a
List<String> . |
static java.lang.Object |
convertTabularDataToMap(javax.management.openmbean.TabularData data)
Receives an instance of a
TabularData whose data is wrapping a
Map and returns a new instance of Map
containing the input information. |
static <T> T |
convertToOpenType(java.lang.Object data,
java.lang.Class<T> openClass,
java.lang.Class<?> realClass)
Convenience method to convert an object,
data from its
Java type realClass to the specified open MBean type
openClass . |
static ClassLoadingMXBeanImpl |
getClassLoadingBean() |
static java.lang.Class |
getClassMaybePrimitive(java.lang.String name)
Convenience method that sets out to return the
Class object for
the specified type named name . |
static CompilationMXBeanImpl |
getCompliationBean() |
static java.util.List<java.lang.management.GarbageCollectorMXBean> |
getGarbageCollectorMXBeans()
Returns a list of all of the instances of
GarbageCollectorMXBean
in this virtual machine. |
static javax.management.openmbean.CompositeType |
getLockInfoCompositeType() |
static java.lang.management.LockInfo[] |
getLockInfosFromCompositeDataArray(javax.management.openmbean.CompositeData[] lockInfosCDArray)
Returns an array of
LockInfo whose elements have been created
from the corresponding elements of the lockInfosCDArray
argument. |
static LoggingMXBeanImpl |
getLoggingBean() |
static MemoryMXBeanImpl |
getMemoryBean() |
static java.util.List<java.lang.management.MemoryManagerMXBean> |
getMemoryManagerMXBeans()
Returns a list of all of the instances of
MemoryManagerMXBean in
this virtual machine. |
static java.util.List<java.lang.management.MemoryPoolMXBean> |
getMemoryPoolMXBeans()
Returns a list of all of the instances of
MemoryPoolMXBean in
this virtual machine. |
static javax.management.openmbean.CompositeType |
getMemoryUsageCompositeType() |
static java.lang.management.MonitorInfo[] |
getMonitorInfosFromCompositeDataArray(javax.management.openmbean.CompositeData[] monitorInfosCDArray)
Returns an array of
MonitorInfo whose elements have been created
from the corresponding elements of the monitorInfosCDArray
argument. |
static OperatingSystemMXBeanImpl |
getOperatingSystemBean() |
static RuntimeMXBeanImpl |
getRuntimeBean() |
static java.lang.StackTraceElement |
getStackTraceFromCompositeData(javax.management.openmbean.CompositeData stackTraceCD)
Convenience method that returns a
StackTraceElement created from
the corresponding CompositeData argument. |
static java.lang.StackTraceElement[] |
getStackTracesFromCompositeDataArray(javax.management.openmbean.CompositeData[] stackTraceDataVal)
Returns an array of
StackTraceElement whose elements have been
created from the corresponding elements of the
stackTraceDataVal argument. |
static ThreadMXBeanImpl |
getThreadBean() |
static javax.management.openmbean.CompositeType |
getThreadInfoCompositeType() |
static <T> boolean |
isANotificationEmitter(java.lang.Class<T> mxbeanInterface)
Convenience method that returns a boolean indication of whether or not
concrete instances of the the supplied interface type
mxbeanInterface should also be implementors of the
interface javax.management.NotificationEmitter . |
static boolean |
isWrapperClass(java.lang.Class<? extends java.lang.Object> wrapper,
java.lang.Class primitive)
Convenience method to determine if the
wrapper
Class
object is really the wrapper class for the
primitive Class object. |
static javax.management.openmbean.CompositeData |
toAvailableProcessorsNotificationInfoCompositeData(AvailableProcessorsNotificationInfo info) |
static javax.management.openmbean.CompositeData |
toLockInfoCompositeData(java.lang.management.LockInfo info) |
static javax.management.openmbean.CompositeData |
toMemoryNotificationInfoCompositeData(java.lang.management.MemoryNotificationInfo info) |
static javax.management.openmbean.CompositeData |
toMemoryUsageCompositeData(java.lang.management.MemoryUsage usage) |
static javax.management.openmbean.CompositeData |
toMonitorInfoCompositeData(java.lang.management.MonitorInfo info) |
static javax.management.openmbean.CompositeData |
toProcessingCapacityNotificationInfoCompositeData(ProcessingCapacityNotificationInfo info) |
static javax.management.openmbean.CompositeData |
toStackTraceElementCompositeData(java.lang.StackTraceElement element) |
static javax.management.openmbean.TabularData |
toSystemPropertiesTabularData(java.util.Map<java.lang.String,java.lang.String> propsMap) |
static javax.management.openmbean.CompositeData |
toThreadInfoCompositeData(java.lang.management.ThreadInfo info) |
static javax.management.openmbean.CompositeData |
toTotalPhysicalMemoryNotificationInfoCompositeData(TotalPhysicalMemoryNotificationInfo info) |
static void |
verifyFieldNames(javax.management.openmbean.CompositeData cd,
java.lang.String[] expected)
Throws an
IllegalArgumentException if the CompositeData
argument cd does not have any of the attributes named in
the expected array of strings. |
static void |
verifyFieldNumber(javax.management.openmbean.CompositeData cd,
int i)
Throws an
IllegalArgumentException if the CompositeData
argument cd does not have the number of attributes
specified in i . |
static void |
verifyFieldTypes(javax.management.openmbean.CompositeData cd,
java.lang.String[] expectedNames,
java.lang.String[] expectedTypes)
Throws an
IllegalArgumentException if the CompositeData
argument cd contains attributes that are not of the exact
types specified in the expectedTypes argument. |
public static final boolean VERBOSE_MODE
public static ClassLoadingMXBeanImpl getClassLoadingBean()
ClassLoadingMXBean
instance.public static MemoryMXBeanImpl getMemoryBean()
MemoryMXBean
instance.public static ThreadMXBeanImpl getThreadBean()
ThreadMXBean
instance.public static RuntimeMXBeanImpl getRuntimeBean()
RuntimeMXBean
instance.public static OperatingSystemMXBeanImpl getOperatingSystemBean()
RuntimeMXBean
instance.public static CompilationMXBeanImpl getCompliationBean()
CompilationMXBean
if available.public static LoggingMXBeanImpl getLoggingBean()
LoggingMXBean
instance.public static java.util.List<java.lang.management.MemoryManagerMXBean> getMemoryManagerMXBeans()
MemoryManagerMXBean
in
this virtual machine. Owing to the dynamic nature of this kind of
MXBean
, it is possible that instances may be created or
destroyed between the invocation and return of this method.MemoryManagerMXBean
s in this
virtual machine.public static java.util.List<java.lang.management.MemoryPoolMXBean> getMemoryPoolMXBeans()
MemoryPoolMXBean
in
this virtual machine. Owing to the dynamic nature of this kind of
MXBean
, it is possible that instances may be created or
destroyed between the invocation and return of this method.MemoryPoolMXBean
s in this
virtual machine.public static java.util.List<java.lang.management.GarbageCollectorMXBean> getGarbageCollectorMXBeans()
GarbageCollectorMXBean
in this virtual machine. Owing to the dynamic nature of this kind of
MXBean
, it is possible that instances may be created or
destroyed between the invocation and return of this method.GarbageCollectorMXBean
s in
this virtual machine.public static void verifyFieldTypes(javax.management.openmbean.CompositeData cd, java.lang.String[] expectedNames, java.lang.String[] expectedTypes)
IllegalArgumentException
if the CompositeData
argument cd
contains attributes that are not of the exact
types specified in the expectedTypes
argument. The
attribute types of cd
must also match the order of types
in expectedTypes
.cd
- a CompositeData
objectexpectedNames
- an array of expected attribute namesexpectedTypes
- an array of type namespublic static void verifyFieldNames(javax.management.openmbean.CompositeData cd, java.lang.String[] expected)
IllegalArgumentException
if the CompositeData
argument cd
does not have any of the attributes named in
the expected
array of strings.cd
- a CompositeData
objectexpected
- an array of attribute names expected in cd
.public static void verifyFieldNumber(javax.management.openmbean.CompositeData cd, int i)
IllegalArgumentException
if the CompositeData
argument cd
does not have the number of attributes
specified in i
.cd
- a CompositeData
objecti
- the number of expected attributes in cd
public static javax.management.openmbean.CompositeData toMemoryUsageCompositeData(java.lang.management.MemoryUsage usage)
usage
- a MemoryUsage
object.CompositeData
object that represents the supplied
usage
object.public static javax.management.openmbean.CompositeType getMemoryUsageCompositeType()
CompositeType
for the MemoryUsage
class.public static javax.management.openmbean.CompositeData toMemoryNotificationInfoCompositeData(java.lang.management.MemoryNotificationInfo info)
info
- a MemoryNotificationInfo
object.CompositeData
object that represents the supplied
info
object.public static javax.management.openmbean.CompositeData toProcessingCapacityNotificationInfoCompositeData(ProcessingCapacityNotificationInfo info)
info
- a ProcessingCapacityNotificationInfo
object.CompositeData
object that represents the supplied
info
object.public static javax.management.openmbean.CompositeData toTotalPhysicalMemoryNotificationInfoCompositeData(TotalPhysicalMemoryNotificationInfo info)
info
- a TotalPhysicalMemoryNotificationInfo
object.CompositeData
object that represents the supplied
info
object.public static javax.management.openmbean.CompositeData toAvailableProcessorsNotificationInfoCompositeData(AvailableProcessorsNotificationInfo info)
info
- a AvailableProcessorsNotificationInfo
object.CompositeData
object that represents the supplied
info
object.public static javax.management.openmbean.CompositeData toThreadInfoCompositeData(java.lang.management.ThreadInfo info)
info
- a ThreadInfo
object.CompositeData
object that represents the supplied
info
object.public static javax.management.openmbean.CompositeData toMonitorInfoCompositeData(java.lang.management.MonitorInfo info)
info
- a MonitorInfo
objectCompositeData
instance that represents the
supplied info
object.public static javax.management.openmbean.CompositeData toLockInfoCompositeData(java.lang.management.LockInfo info)
info
- a LockInfo
objectCompositeData
instance that represents the
supplied info
object.public static javax.management.openmbean.CompositeData toStackTraceElementCompositeData(java.lang.StackTraceElement element)
element
- a StackTraceElement
object.CompositeData
object that represents the supplied
element
object.public static javax.management.openmbean.CompositeType getLockInfoCompositeType()
CompositeType
for the LockInfo
classpublic static javax.management.openmbean.CompositeType getThreadInfoCompositeType()
CompositeType
for the ThreadInfo
class.public static java.util.List<java.lang.String> convertStringArrayToList(java.lang.String[] data)
String
to a
List<String>
.data
- an array of String
List<String>
public static java.lang.Object convertTabularDataToMap(javax.management.openmbean.TabularData data)
TabularData
whose data is wrapping a
Map
and returns a new instance of Map
containing the input information.data
- an instance of TabularData
that may be mapped
to a Map
.Map
containing the information originally wrapped
in the data
input.java.lang.IllegalArgumentException
- if data
has a CompositeType
that does not contain exactly two items (i.e. a key and a
value).public static <T> T convertFromCompositeData(javax.management.openmbean.CompositeData data, java.lang.Class<T> realClass) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
T
from the supplied
CompositeData
object whose type maps to T
.T
- the type of object wrapped by the CompositeData
.data
- an instance of CompositeData
that maps to an
instance of T
realClass
- the Class
object for type T
T
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
public static <T> T convertFromOpenType(java.lang.Object data, java.lang.Class<?> openClass, java.lang.Class<T> realClass) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
openClass
and return
it in an instance of the type specified in realClass
.T
- data
- an instance of the type named openTypeName
openClass
- realClass
- realTypeName
containing
all the state in the input data
object.java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.SecurityException
public static <T> T convertToOpenType(java.lang.Object data, java.lang.Class<T> openClass, java.lang.Class<?> realClass)
data
from its
Java type realClass
to the specified open MBean type
openClass
.T
- the open MBean classdata
- the object to be convertedopenClass
- the open MBean classrealClass
- the real Java type of data
openClass
public static javax.management.openmbean.TabularData toSystemPropertiesTabularData(java.util.Map<java.lang.String,java.lang.String> propsMap)
propsMap
- a Map<String, String%gt;
of the system
properties.RuntimeMXBean.getSystemProperties()
) wrapped in a
TabularData
.public static java.lang.Class getClassMaybePrimitive(java.lang.String name) throws java.lang.ClassNotFoundException
Class
object for
the specified type named name
. Unlike the
Class.forName(java.lang.String)
method, this will work even for
primitive types.name
- the name of a Java typeClass
object for the type name
java.lang.ClassNotFoundException
- if name
does not correspond to any known type
(including primitive types).public static boolean isWrapperClass(java.lang.Class<? extends java.lang.Object> wrapper, java.lang.Class primitive)
wrapper
Class
object is really the wrapper class for the
primitive
Class
object.wrapper
- primitive
- true
if the wrapper
class is the
wrapper class for primitive
. Otherwise
false
.public static <T> boolean isANotificationEmitter(java.lang.Class<T> mxbeanInterface)
mxbeanInterface
should also be implementors of the
interface javax.management.NotificationEmitter
.T
- mxbeanInterface
- true
if instances of type
mxbeanInterface
should also implement
javax.management.NotificationEmitter
. Otherwise,
false
.public static java.lang.StackTraceElement[] getStackTracesFromCompositeDataArray(javax.management.openmbean.CompositeData[] stackTraceDataVal)
StackTraceElement
whose elements have been
created from the corresponding elements of the
stackTraceDataVal
argument.stackTraceDataVal
- an array of CompositeData
objects, each one
representing a StackTraceElement
.StackTraceElement
objects built using
the data discovered in the corresponding elements of
stackTraceDataVal
.java.lang.IllegalArgumentException
- if any of the elements of stackTraceDataVal
do
not correspond to a StackTraceElement
with the
following attributes:
className
(java.lang.String
)
methodName
(
java.lang.String
)
fileName
(java.lang.String
)
lineNumbercode> (java.lang.Integer
)
nativeMethod
(java.lang.Boolean
)
public static java.lang.management.LockInfo[] getLockInfosFromCompositeDataArray(javax.management.openmbean.CompositeData[] lockInfosCDArray)
LockInfo
whose elements have been created
from the corresponding elements of the lockInfosCDArray
argument.lockInfosCDArray
- an array of CompositeData
objects, each one
representing a LockInfo
.LockInfo
objects built using the data
discovered in the corresponding elements of
lockInfosCDArray
.java.lang.IllegalArgumentException
- if any of the elements of lockInfosCDArray
do
not correspond to a LockInfo
with the
following attributes:
className
(java.lang.String
)
identityHashCode
(java.lang.Integer
)
public static java.lang.management.MonitorInfo[] getMonitorInfosFromCompositeDataArray(javax.management.openmbean.CompositeData[] monitorInfosCDArray)
MonitorInfo
whose elements have been created
from the corresponding elements of the monitorInfosCDArray
argument.monitorInfosCDArray
- an array of CompositeData
objects, each one
representing a MonitorInfo
.MonitorInfo
objects built using the
data discovered in the corresponding elements of
monitorInfosCDArray
.java.lang.IllegalArgumentException
- if any of the elements of monitorInfosCDArray
do not correspond to a MonitorInfo
with the
following attributes:
lockedStackFrame
(javax.management.openmbean.CompositeData
)
lockedStackDepth
(
java.lang.Integer
)
lockedStackFrame
attribute must correspond
to a java.lang.StackTraceElement
which has the
following attributes:
className
(java.lang.String
)
methodName
(java.lang.String
)
fileName
(java.lang.String
)
lineNumber
(java.lang.Integer
)
nativeMethod
(java.lang.Boolean
)
public static java.lang.StackTraceElement getStackTraceFromCompositeData(javax.management.openmbean.CompositeData stackTraceCD)
StackTraceElement
created from
the corresponding CompositeData
argument.stackTraceCD
- a CompositeData
that wraps a
StackTraceElement
StackTraceElement
object built using the data
discovered in the stackTraceCD
.java.lang.IllegalArgumentException
- if the stackTraceCD
does not correspond to a
StackTraceElement
with the following
attributes:
className
(java.lang.String
)
methodName
(
java.lang.String
)
fileName
(java.lang.String
)
lineNumbercode> (java.lang.Integer
)
nativeMethod
(java.lang.Boolean
)