如何以编程方式检查JMX MBean操作和属性? [英] How to programmatically check JMX MBean operations and attributes?
问题描述
假设我们有一个具有以下属性和操作的MBean.
Suppose we have a MBean that has the following attributes and operations.
属性: 姓名 大小
操作: getName() getSize()
Operations: getName() getSize()
是否可以通过编程方式检查属性和操作?我一直在使用IBM WebSphere MBean,它们的文档不是很好.
Is there a way to programmatically check for the attributes and operations? I've been working with the IBM WebSphere MBeans and their documentation isn't very good.
例如,如果您访问 IBMs Infocenter ,然后导航至网络部署"->参考"->编程接口"->"Mbean接口"->"ThreadPool".它们只列出了属性,没有任何操作.
For example, if you go to IBMs Infocenter and navigate to Network Deployment -> Reference -> Programming interfaces -> Mbean interfaces -> ThreadPool. They only have attributes listed and no operations.
实际上,我可以使用WebSphere wsadmin工具进行检查,以查看操作和属性.我想知道是否可以对所有MBean做到这一点.
Using the WebSphere wsadmin tool, I can actually check to see the operations and attributes. I'd like to know if there's a way to do this with all MBeans.
wsadmin>print Help.attributes(object)
Attribute Type Access
name java.lang.String RO
maximumSize int RW
minimumSize int RW
inactivityTimeout long RW
growable boolean RW
stats javax.management.j2ee.statistics.Stats RO
wsadmin>print Help.operations(object)
Operation
java.lang.String getName()
int getMaximumPoolSize()
void setMaximumPoolSize(int)
int getMinimumPoolSize()
void setMinimumPoolSize(int)
long getKeepAliveTime()
void setKeepAliveTime(long)
boolean isGrowAsNeeded()
void setGrowAsNeeded(boolean)
javax.management.j2ee.statistics.Stats getStats()
推荐答案
如何以编程方式检查JMX MBean操作和属性?
How to programmatically check JMX MBean operations and attributes?
我不太清楚您是在谈论以编程方式从当前JVM内部还是从客户端远程查找MBean.有许多JMX客户端库.您可能要尝试使用 SimpleJMX软件包.
I can't quite tell if you are talking about programmatically finding the MBeans from inside the current JVM or remotely from a client. There are a number of JMX client libraries. You might want to try my SimpleJMX package.
使用我的代码,您可以执行以下操作:
With my code you can do something like:
JmxClient client = new JmxClient(hostName, port);
Set<ObjectName> objectNames = getBeanNames()
for (ObjectName name : objectNames) {
MBeanAttributeInfo[] attributes = getAttributesInfo(name);
MBeanOperationInfo[] operations = getOperationsInfo(name);
}
如果您询问当前的JVM,那么您应该能够以这种方式从内部Bean获取Bean信息:
If you are asking about the current JVM then you should be able to get bean information from the internal beans this way:
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = server.queryNames(null, null);
for (ObjectName name : objectNames) {
MBeanInfo info = server.getMBeanInfo(name);
}
这篇关于如何以编程方式检查JMX MBean操作和属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!