我正在将一个servlet实现为一个JMX管理器,它运行在所有受监控的servlet运行的Tomcat的同一个实例中.当我打开JConsole时,我可以看到被监控的servlet的数据.在我的管理器servlet中,我可以枚举所有可用的标准MBean,包括我在受监控的servlet中创建的MBean,使用如下代码:
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi" );
mConnector = JMXConnectorFactory.connect( url );
mMBSC = mConnector.getMBeanServerConnection();
mObjectName = new ObjectName( "com.blahCompany.blah.blah:type=BlahBlah" );
// just looking for one specific bean
Set myMbean = mMBSC.queryNames( mObjectName, null );
if( myMBean.size() == 1 ) // I know it exists
{
MBeanInfo mbeanInfo = mMBSC.getMBeanInfo( );
MBeanAttributeInfo[] mbeanAttributeInfos = mbeanInfo.getAttributes();
for( MBeanAttributeInfo attribInfo : mbeanAttributeInfos )
{
if( attribInfo.isReadable() )
{
String attribName = attribInfo.getName();
String attribReturnType = attribInfo.getType();
// The data's somewhere ... where????
// In the MBeanInfo?
// In the MBeanAttributeInfo??
}
}
}
问题是我不知道如何从这些MBean中实际提取数据.答案必须是明显的,因为似乎没有其他人问过,但我确实有一个礼物可以忽略那些显而易见的东西.非常感谢您的帮助.
法案