【发布时间】:2011-07-15 05:01:50
【问题描述】:
这是我在 StackOverflow 上的第一个问题,所以请多多包涵。
我想达到什么目的?
我需要编写一个独立程序来访问 Websphere Application Server 的一个或多个特定实例并从中获取详细信息。就我的研究而言,有两种方法可以做到这一点。
- 适配器
- 连接器
我目前正在采用“连接器”方法以及 SOAP 连接器(因为它的防火墙友好性)
所以,我的代码应该是这样的......
// Initialize the AdminClient.
Properties adminProps = new Properties();
adminProps.setProperty("type", AdminClient.CONNECTOR_TYPE_SOAP );
adminProps.setProperty("host", "localhost");
adminProps.setProperty("port", "8880");
AdminClient adminClient = AdminClientFactory.createAdminClient(adminProps);
String query = "WebSphere:*";
//String query = "WebSphere:type=Server,*";
ObjectName queryName = new ObjectName(query);
Set s = adminClient.queryNames(queryName, null);
if (!s.isEmpty()) {
iter = s.iterator();
while (iter.hasNext()) {
ObjectName nodeagent = (ObjectName) iter.next();
System.out.println("*********************************************");
System.out.println("KeyPropertyList: " + nodeagent.getKeyPropertyListString());
}
}
通过这段代码,我可以获取该特定 WAS 实例(C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01)上所有 MBean 的列表,并成功打印密钥- 属性列表。
现在我有一个 MBean 列表。接下来是什么? 链接:_http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.javadoc.doc/web/mbeanDocs/index.html
这是我的查询:
如何获取我感兴趣的特定 MBean 的实例并获取所有相关属性?
例如:
AppManagement appM = AppManagementProxy.getJMXProxyForClient (adminClient);
System.out.println(appM.listApplications(null, null, null));
将列出该特定 WAS 实例上的所有应用程序
[查询、SamplesGallery、ivtApp、DefaultApplication、PlantsByWebSphere]
我有兴趣了解有关已安装应用程序的更多信息,比如它们是否已启动并正在运行?如果是这样,IP 地址、内部版本号、是否正在维护等,(仅引用它们作为示例)如果我可以获得 MBean 可以提供的应用程序的所有可能详细信息,那么它将完成我的任务(部分)
上述只是一个示例,我想从 MBean 中获得更多信息。因此,请提供一个解决方案/示例代码,以帮助我从 WAS 实例必须提供的任何 MBean 中获取信息。 (使用 JMX)
其他细节: IBM WebSphere Application Server,7.0.0.0(基本安装)
提前致谢, 阿杰
【问题讨论】: