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


Java MBeanServerFactory.createMBeanServer方法代码示例

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


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

示例1: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    if (System.getSecurityManager() == null)
        throw new IllegalStateException("No security manager installed!");

    System.out.println("java.security.policy=" +
                       System.getProperty("java.security.policy"));

    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    // Register the MLetMBean
    //
    System.out.println("Create MLet MBean");
    ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean");
    mbs.createMBean("javax.management.loading.MLet", mlet);
    // Test OK!
    //
    System.out.println("Bye! Bye!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:MLetCommand.java

示例2: ConfigRegistryImpl

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public ConfigRegistryImpl(final ModuleFactoriesResolver resolver, final MBeanServer configMBeanServer,
        final BaseJMXRegistrator baseJMXRegistrator, final BindingContextProvider bindingContextProvider) {
    this.resolver = resolver;
    this.beanToOsgiServiceManager = new BeanToOsgiServiceManager();
    this.configMBeanServer = configMBeanServer;
    this.baseJMXRegistrator = baseJMXRegistrator;
    this.bindingContextProvider = bindingContextProvider;
    this.registryMBeanServer = MBeanServerFactory
            .createMBeanServer("ConfigRegistry" + configMBeanServer.getDefaultDomain());
    this.transactionsMBeanServer = MBeanServerFactory
            .createMBeanServer("ConfigTransactions" + configMBeanServer.getDefaultDomain());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:13,代码来源:ConfigRegistryImpl.java

示例3: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    JMXServiceURL inputAddr =
        new JMXServiceURL("service:jmx:iiop://");
    JMXConnectorServer s;
    try {
        s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
    } catch (java.net.MalformedURLException x) {
        try {
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
            throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
        } catch (ClassNotFoundException expected) { }
        System.out.println("IIOP protocol not supported, test skipped");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    mbs.registerMBean(s, new ObjectName("a:b=c"));
    s.start();
    JMXServiceURL outputAddr = s.getAddress();
    if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
        throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
                                   outputAddr);
    }
    System.out.println("IIOP URL path looks OK: " + outputAddr);
    JMXConnector c = JMXConnectorFactory.connect(outputAddr);
    System.out.println("Successfully got default domain: " +
                       c.getMBeanServerConnection().getDefaultDomain());
    c.close();
    s.stop();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:IIOPURLTest.java

示例4: jmxConnectorServerFactoryTests

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
private int jmxConnectorServerFactoryTests() {
    int errorCount = 0;
    echo("");
    echo(dashedMessage("Run JMXConnectorServerFactory Tests"));
    for (int i = 0; i < maps.length - 1; i++) {
        echo("\n>>> JMXConnectorServerFactory Test [" + i + "]");
        try {
            echo("\tMap = " + maps[i]);
            echo("\tCreate the MBean server");
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();
            echo("\tCreate the RMI connector server");
            JMXServiceURL url =
                new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" +
                                  port + "/JMXConnectorServerFactory" + i);
            JMXConnectorServer jmxcs =
                JMXConnectorServerFactory.newJMXConnectorServer(url,
                                                                maps[i],
                                                                mbs);
            echo("\tStart the RMI connector server");
            jmxcs.start();
            echo("\tCall RMIConnectorServer.toJMXConnector(Map)");
            jmxcs.toJMXConnector(maps[i]);
            echo("\tStop the RMI connector server");
            jmxcs.stop();
            echo("\tTest [" + i + "] PASSED!");
        } catch (Exception e) {
            errorCount++;
            echo("\tTest [" + i + "] FAILED!");
            e.printStackTrace(System.out);
        }
    }
    if (errorCount == 0) {
        echo("");
        echo(dashedMessage("JMXConnectorServerFactory Tests PASSED!"));
    } else {
        echo("");
        echo(dashedMessage("JMXConnectorServerFactory Tests FAILED!"));
    }
    return errorCount;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:MapNullValuesTest.java

示例5: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
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!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SystemClassLoaderTest.java

示例6: MBeanRegistry

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:10,代码来源:MBeanRegistry.java

示例7: start

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
/**
 * 
 * 启动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);
	}
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:32,代码来源:JmxServer.java

示例8: getMBeanServer

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
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;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:11,代码来源:ClusterJmxHelper.java

示例9: Client

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
/**
 * Client Constructor.
 * @param parameter start parameter from cli
 * @param runDirect decide if the client should be started direct (long running)
 */
public Client(final CliParameter parameter, final boolean runDirect){
    this.parameter = parameter;
    if(this.parameter.jmx){
        this.mbs = MBeanServerFactory.createMBeanServer(StringGenerator.nextRandomString(5));
        this.buildClientJmxDisc();
        this.buildClientJmxNetwork();
        this.buildClientJmxReader();
        this.buildClientJmxController();
    }else{
        this.mbs = null;
    }
    if(runDirect)
        this.run();
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:20,代码来源:Client.java

示例10: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    System.out.println("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();

    // Get the JMX implementation version from the MBeanServerDelegateMBean
    //
    System.out.println("Get the JMX implementation version");
    ObjectName mbsdName =
        new ObjectName("JMImplementation:type=MBeanServerDelegate");
    String mbsdAttribute = "ImplementationVersion";
    String mbsdVersion = (String) mbs.getAttribute(mbsdName, mbsdAttribute);

    // Display JMX implementation version and JVM implementation version
    //
    System.out.println("JMX implementation version          = " +
                       mbsdVersion);
    System.out.println("Java Runtime implementation version = " +
                       args[0]);

    // Check JMX implementation version vs. JVM implementation version
    //
    if (Boolean.valueOf(args[1]).booleanValue()) {
        if (!mbsdVersion.equals(args[0]))
            throw new IllegalArgumentException(
              "JMX and Java Runtime implementation versions do not match!");
        // Test OK!
        //
        System.out.println("JMX and Java Runtime implementation " +
                           "versions match!");
    } else {
        // Test OK!
        //
        System.out.println("JMX and Java Runtime implementation " +
                           "versions do not match because the test " +
                           "is using an unbundled version of JMX!");
    }
    System.out.println("Bye! Bye!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:ImplVersionCommand.java

示例11: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    boolean expectException =
            (System.getProperty("jmx.mxbean.multiname") == null);
    try {
        ObjectName objectName1 = new ObjectName("test:index=1");
        ObjectName objectName2 = new ObjectName("test:index=2");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
        MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();

        mbs.registerMBean(mxBeanObject, objectName1);

        mbs.registerMBean(mxBeanObject, objectName2);

        if (expectException) {
            throw new Exception("TEST FAILED: " +
                    "InstanceAlreadyExistsException was not thrown");
        } else
            System.out.println("Correctly got no exception with compat property");
    } catch (InstanceAlreadyExistsException e) {
        if (expectException) {
            System.out.println("Got expected InstanceAlreadyExistsException:");
            e.printStackTrace(System.out);
        } else {
            throw new Exception(
                    "TEST FAILED: Got exception even though compat property set", e);
        }
    }
    System.out.println("TEST PASSED");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SameObjectTwoNamesTest.java

示例12: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Register the MBean
        //
        System.out.println("Create a TestDynamicMBean");
        TestDynamicMBean obj = new TestDynamicMBean();
        ObjectName n = new ObjectName("d:k=v");
        System.out.println("Register a TestDynamicMBean");
        mbs.registerMBean(obj, n);
        obj.throwException = true;
        System.out.println("Unregister a TestDynamicMBean");
        try {
            mbs.unregisterMBean(n);
        } catch (Exception e) {
            throw new IllegalArgumentException("Test failed", e);
        }
        boolean isRegistered = mbs.isRegistered(n);
        System.out.println("Is MBean Registered? " + isRegistered);

        if (isRegistered) {
            throw new IllegalArgumentException(
                "Test failed: the MBean is still registered");
        } else {
            System.out.println("Test passed");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:UnregisterMBeanExceptionTest.java

示例13: PogamutMBeanServer

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public PogamutMBeanServer() {
	this(MBeanServerFactory.createMBeanServer());
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:4,代码来源:PogamutMBeanServer.java

示例14: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        server.start();

        JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        synchronized(li) {
            while (li.received < 1) {
                li.wait();
            }
        }

        if (li.received != 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:EmptyDomainNotificationTest.java

示例15: main

import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:GetMBeansFromURLTest.java


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