本文整理汇总了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!");
}
示例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());
}
示例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();
}
示例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;
}
示例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!");
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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!");
}
示例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");
}
示例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");
}
}
示例13: PogamutMBeanServer
import javax.management.MBeanServerFactory; //导入方法依赖的package包/类
public PogamutMBeanServer() {
this(MBeanServerFactory.createMBeanServer());
}
示例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.");
}
示例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);
}