當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。