当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServerConnection.getDomains方法代码示例

本文整理汇总了Java中javax.management.MBeanServerConnection.getDomains方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.getDomains方法的具体用法?Java MBeanServerConnection.getDomains怎么用?Java MBeanServerConnection.getDomains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServerConnection的用法示例。


在下文中一共展示了MBeanServerConnection.getDomains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException,
        MalformedObjectNameException, InstanceNotFoundException,
        AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException, IntrospectionException {
    String domainName = "MyMBean";
    int rmiPort = 1099;
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
    // 可以类比HelloAgent.java中的那句:
    // JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    JMXConnector jmxc = JMXConnectorFactory.connect(url);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    //print domains
    System.out.println("Domains:------------------");
    String domains[] = mbsc.getDomains();
    for(int i=0;i<domains.length;i++){
        System.out.println("\tDomain["+i+"] = "+domains[i]);
    }
    //MBean count
    System.out.println("MBean count = "+mbsc.getMBeanCount());
    //process attribute
    ObjectName mBeanName = new ObjectName(domainName+":name=HelloWorld");
    mbsc.setAttribute(mBeanName, new Attribute("Name","zzh"));//注意这里是Name而不是name
    System.out.println("Name = "+mbsc.getAttribute(mBeanName, "Name"));

    //接下去是执行Hello中的printHello方法,分别通过代理和rmi的方式执行
    //via proxy
    HelloMBean proxy = MBeanServerInvocationHandler.newProxyInstance(mbsc, mBeanName, HelloMBean.class, false);
    proxy.printHello();
    proxy.printHello("jizhi boy");
    //via rmi
    mbsc.invoke(mBeanName, "printHello", null, null);
    mbsc.invoke(mBeanName, "printHello", new String[]{"jizhi gril"}, new String[]{String.class.getName()});

    //get mbean information
    MBeanInfo info = mbsc.getMBeanInfo(mBeanName);
    System.out.println("Hello Class: "+info.getClassName());
    for(int i=0;i<info.getAttributes().length;i++){
        System.out.println("Hello Attribute:"+info.getAttributes()[i].getName());
    }
    for(int i=0;i<info.getOperations().length;i++){
        System.out.println("Hello Operation:"+info.getOperations()[i].getName());
    }

    //ObjectName of MBean
    System.out.println("all ObjectName:--------------");
    Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
    for(Iterator<ObjectInstance> it = set.iterator();it.hasNext();){
        ObjectInstance oi = it.next();
        System.out.println("\t"+oi.getObjectName());
    }
    jmxc.close();
}
 
开发者ID:breakEval13,项目名称:rocketmq-flink-plugin,代码行数:54,代码来源:Client.java


注:本文中的javax.management.MBeanServerConnection.getDomains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。