java类javax.management.MBeanServerFactory的实例源码

JmxServer.java 文件源码 项目:asura 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 
 * 启动JMXConnectorServer
 *
 * @author zhangshaobin
 * @created 2012-12-28 下午4:00:59
 *
 * @throws IOException
 */
private void start() {
    if (null != server)
        return;
    try {
        //          platformServer = ManagementFactory.getPlatformMBeanServer();
        server = MBeanServerFactory.createMBeanServer("Asura");
        JMXServiceURL url = new JMXServiceURL("jmxmp", null, port);
        //          JMXServiceURL platformUrl = new JMXServiceURL("jmxmp", null, 9021);
        //          platformConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(platformUrl, null, platformServer);
        //          platformConnectorServer.start();
        //          System.out.println("JMX PlatformServer started! Used port 9020.");
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
        connectorServer.start();
        System.out.println(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date())
                + "JMX Server started! used port:" + port);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date())
                + "JMX Server started failed!" + " " + e.getMessage());
        System.exit(1);
    }
}
DefaultLoaderRepository.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
private static Class<?> load(ClassLoader without, String className)
        throws ClassNotFoundException {
    final List<MBeanServer> mbsList = MBeanServerFactory.findMBeanServer(null);

    for (MBeanServer mbs : mbsList) {
        ClassLoaderRepository clr = mbs.getClassLoaderRepository();
        try {
            return clr.loadClassWithout(without, className);
        } catch (ClassNotFoundException e) {
            // OK : Try with next one...
        }
    }
    throw new ClassNotFoundException(className);
}
MBeanUtil.java 文件源码 项目:monarch 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Create and configure (if necessary) and return the <code>MBeanServer</code> with which we will
 * be registering our <code>ModelMBean</code> implementations.
 *
 * @see javax.management.MBeanServer
 */
static synchronized MBeanServer createMBeanServer() {
  if (mbeanServer == null) {
    mbeanServer = MBeanServerFactory.createMBeanServer(DEFAULT_DOMAIN);
  }
  return mbeanServer;
}
ClusterJmxHelper.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 31 收藏 0 点赞 0 评论 0
public static MBeanServer getMBeanServer() throws Exception {
    if (mbeanServer == null) {
        if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
            mbeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
        } else {
            mbeanServer = MBeanServerFactory.createMBeanServer();
        }
    }
    return mbeanServer;
}
DefaultLoaderRepository.java 文件源码 项目:jdk8u-jdk 阅读 19 收藏 0 点赞 0 评论 0
private static Class<?> load(ClassLoader without, String className)
        throws ClassNotFoundException {
    final List<MBeanServer> mbsList = MBeanServerFactory.findMBeanServer(null);

    for (MBeanServer mbs : mbsList) {
        ClassLoaderRepository clr = mbs.getClassLoaderRepository();
        try {
            return clr.loadClassWithout(without, className);
        } catch (ClassNotFoundException e) {
            // OK : Try with next one...
        }
    }
    throw new ClassNotFoundException(className);
}
AvoidGetMBeanInfoCallsTest.java 文件源码 项目:jdk8u-jdk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Standalone entry point.
 *
 * Run the test and report to stdout.
 */
public static void main(String args[]) throws Exception {

    echo(">>> Create MBeanServer");
    MBeanServer server = MBeanServerFactory.newMBeanServer();

    echo(">>> Default Domain: " + server.getDefaultDomain());

    echo(">>> Create and register Test MBean");
    Test mbean = new Test();
    ObjectName name = ObjectName.getInstance(":type=Test");
    server.registerMBean(mbean, name);

    echo(">>> Set entered flag to false in Test MBean");
    mbean.entered = false;

    echo(">>> Query Names:");
    Set<ObjectName> names = server.queryNames(null, null);
    for (ObjectName on : names) {
        echo("\t" + on.toString());
    }

    echo(">>> Entered flag = " + mbean.entered);

    if (mbean.entered) {
        echo(">>> Test FAILED!");
        throw new IllegalArgumentException("getMBeanInfo got called");
    } else {
        echo(">>> Test PASSED!");
    }
}
MBeanRegistry.java 文件源码 项目:ZooKeeper 阅读 23 收藏 0 点赞 0 评论 0
public MBeanRegistry () {
    try {
        mBeanServer = ManagementFactory.getPlatformMBeanServer();        
    } catch (Error e) {
        // Account for running within IKVM and create a new MBeanServer
        // if the PlatformMBeanServer does not exist.
        mBeanServer =  MBeanServerFactory.createMBeanServer();
    }
}
JMXProxyTest.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
private static void testNonCompliant(Class<?> iface, boolean isMx) throws Exception {
    try {
        System.out.println("Creating a proxy for non-compliant " +
                           (isMx ? "MXBean" : "MBean") + " " +
                           iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        if (isMx) {
            JMX.newMXBeanProxy(mbs, on, iface);
        } else {
            JMX.newMBeanProxy(mbs, on, iface);
        }
        fail("Created a proxy for non-compliant " +
             (isMx ? "MXBean" : "MBean") + " - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("Proxy not created");
        } else {
            throw e;
        }
    }
}
JMXProxyTest.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
private static void testCompliant(Class<?> iface, boolean isMx) throws Exception {
    try {
        System.out.println("Creating a proxy for compliant " +
                           (isMx ? "MXBean" : "MBean") + " " +
                           iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        if (isMx) {
            JMX.newMXBeanProxy(mbs, on, iface);
        } else {
            JMX.newMBeanProxy(mbs, on, iface);
        }
        success("Created a proxy for compliant " +
                (isMx ? "MXBean" : "MBean") + " - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
SystemClassLoaderTest.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();

    ClassLoader mbsClassLoader = mbs.getClass().getClassLoader();

    String testClassName = Test.class.getName();

    // Check that the MBeanServer class loader does not know our test class
    try {
        Class.forName(testClassName, true, mbsClassLoader);
        System.out.println("TEST IS INVALID: MBEANSERVER'S CLASS LOADER " +
                           "KNOWS OUR TEST CLASS");
        System.exit(1);
    } catch (ClassNotFoundException e) {
        // As required
    }

    // Register the MBean
    //
    System.out.println("Create MBean from this class");
    ObjectName objectName = new ObjectName("whatever:type=whatever");
    mbs.createMBean(testClassName, objectName);
    // Test OK!
    //
    System.out.println("Bye! Bye!");
}


问题


面经


文章

微信
公众号

扫码关注公众号