package wrox.ch12.jmx;
import java.util.Iterator;
import java.util.Set;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.Query;
import javax.management.QueryExp;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class RemoteClient {
MBeanServerConnection connection = null;
public RemoteClient() throws Exception {
JMXServiceURL url = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://localhost:9999/server");
JMXConnector connector = JMXConnectorFactory.connect(url);
connection = connector.getMBeanServerConnection();
}
void deploy() throws Exception {
connection.createMBean("wrox.ch12.jmx.Worker",
new ObjectName("wrox.ch12.jmx:type=Worker,number=1"));
connection.createMBean("wrox.ch12.jmx.Worker",
new ObjectName("wrox.ch12.jmx:type=Worker,number=2"));
connection.createMBean("wrox.ch12.jmx.Worker",
new ObjectName("wrox.ch12.jmx:type=Worker,number=3"));
}
void lookup() throws Exception {
ObjectName on = new ObjectName("wrox.ch12.jmx:*");
Set set = connection.queryNames(on, null);
for (Iterator iter = set.iterator(); iter.hasNext();) {
ObjectName bean = (ObjectName) iter.next();
System.out.println("deployed..=" + bean.toString());
}
}
void checkRunning() throws Exception {
ObjectName on = new ObjectName("wrox.ch12.jmx:*");
QueryExp exp = Query.eq(Query.attr("Running"), Query.value(true));
Set set = connection.queryNames(on, exp);
for (Iterator iter = set.iterator(); iter.hasNext();) {
ObjectName bean = (ObjectName) iter.next();
System.out.println("running.. MBean =" + bean.toString());
}
}
void remove() throws Exception {
ObjectName on = new ObjectName("wrox.ch12.jmx:*");
Set set = connection.queryNames(on, null);
for (Iterator iter = set.iterator(); iter.hasNext();) {
ObjectName bean = (ObjectName) iter.next();
System.out.println("removing..=" + bean.toString());
connection.unregisterMBean(bean);
}
}
public void addMonitor( ) throws Exception {
connection.createMBean("javax.management.monitor.StringMonitor", new ObjectName("wrox.ch12.jmx:name=WorkMonitor"));
}
public static void main(String[] args) throws Exception {
RemoteClient rc = new RemoteClient();
rc.remove();
rc.deploy();
rc.lookup();
rc.checkRunning();
rc.addMonitor();
}
}
Oliver_Wu
- 粉丝: 1
- 资源: 3
最新资源
- 【岗位说明】外贸业务员岗位职责.docx
- 【岗位说明】细述贸易公司采购员职责.doc
- 【岗位说明】外贸专员工作岗位职责.doc
- opencv-python-headless-4.6.0.66-cp36-abi3-win-amd64.whl
- 【岗位说明】食品车间员工岗位职责.docx
- 【岗位说明】食品厂厂长岗位职责.doc
- 【岗位说明】食品公司各岗位职责01.doc
- 【岗位说明】食品有限公司岗位职责说明书.doc
- 【岗位说明】食品公司各岗位职责02.doc
- 【岗位说明】餐厅厨师岗位职责.doc
- 【岗位说明】餐厅接待员岗位职责.doc
- 【岗位说明】餐厅业务员岗位职责.doc
- 【岗位说明】餐厅人员的岗位职责.doc
- 【岗位说明】餐饮部岗位职责.doc
- 【岗位说明】餐饮部各岗位职责.doc
- 【岗位说明】餐饮部管理员岗位职责.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈