use of javax.management.MBeanServer in project opennms by OpenNMS.
the class PlatformMBeanServerConnector method createConnection.
public JmxServerConnectionWrapper createConnection() {
final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
final JmxServerConnectionWrapper jmxConnectionWrapper = new JmxServerConnectionWrapper() {
@Override
public MBeanServerConnection getMBeanServerConnection() {
return platformMBeanServer;
}
@Override
public void close() {
}
};
return jmxConnectionWrapper;
}
use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class PreRegisterNameTest method main.
public static void main(String[] args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (Class<?> c : new Class<?>[] { Spume.class, Thing.class, XSpume.class, XThing.class }) {
for (ObjectName n : new ObjectName[] { null, new ObjectName("a:b=c") }) {
System.out.println("Class " + c.getName() + " with name " + n + "...");
ObjectName realName = new ObjectName("a:type=" + c.getName());
Constructor<?> constr = c.getConstructor(ObjectName.class);
Object mbean = constr.newInstance(realName);
ObjectInstance oi;
String what = "Registering MBean of type " + c.getName() + " under name " + "<" + n + ">: ";
try {
oi = mbs.registerMBean(mbean, n);
} catch (Exception e) {
e.printStackTrace();
fail(what + " got " + e);
continue;
}
ObjectName registeredName = oi.getObjectName();
if (!registeredName.equals(realName))
fail(what + " registered as " + registeredName);
if (!mbs.isRegistered(realName)) {
fail(what + " not registered as expected");
}
mbs.unregisterMBean(registeredName);
}
}
System.err.flush();
if (failures == 0)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: " + failure);
}
use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class RandomMXBeanTest method main.
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("a:b=c");
StupidMXBean stupid = new StupidImpl();
mbs.registerMBean(stupid, name);
ObjectName referName = new ObjectName("a:c=d");
mbs.registerMBean(new ReferImpl(stupid), referName);
System.out.println(mbs.getMBeanInfo(name));
StupidMXBean stupid2 = (StupidMXBean) Proxy.newProxyInstance(StupidMXBean.class.getClassLoader(), new Class<?>[] { StupidMXBean.class }, new WrapInvocationHandler(stupid));
ObjectName stupidName2 = new ObjectName("a:d=e");
mbs.registerMBean(stupid2, stupidName2);
Field zero = StupidMXBean.class.getField("ZERO");
System.out.println("Zero field = " + zero.get(null));
test(mbs, MerlinMXBean.class);
test(mbs, TigerMXBean.class);
StupidMXBean proxy = JMX.newMXBeanProxy(mbs, name, StupidMXBean.class);
System.out.println("Zero = " + proxy.getZero());
System.out.println("One = " + proxy.identity(1));
ReferMXBean referProxy = JMX.newMXBeanProxy(mbs, referName, ReferMXBean.class);
StupidMXBean stupidProxy2 = referProxy.getStupid();
System.out.println("Same proxy: " + (proxy == stupidProxy2));
Method[] methods = StupidMXBean.class.getMethods();
for (Method method : methods) {
if (method.getParameterTypes().length == 0)
method.invoke(proxy, new Object[0]);
}
}
use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class SupportedQueryTypesTest method run.
public void run(Map<String, Object> args) {
int errorCount = 0;
ObjectName on = null;
ObjectName serverDelegateObjectName = null;
JMXConnectorServer cs = null;
JMXConnector cc = null;
System.out.println("SupportedQueryTypesTest::run: Start");
try {
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
mbsc = cc.getMBeanServerConnection();
// Create and register the ServerDelegate MBean on the remote MBeanServer
String serverDelegateClassName = ServerDelegate.class.getName();
serverDelegateObjectName = new ObjectName("defaultDomain:class=" + serverDelegateClassName);
mbsc.createMBean(serverDelegateClassName, serverDelegateObjectName);
// Retrieve the MBean class name
mbeanClassName = (String) args.get("-mbeanClassName");
on = new ObjectName("defaultDomain:class=" + mbeanClassName);
// Create and register the MBean on the remote MBeanServer
System.out.println("SupportedQueryTypesTest::run: CREATE " + mbeanClassName + " on the remote MBeanServer with name " + on);
mbsc.createMBean(mbeanClassName, on);
// Create a QueryFactory and setup which query we'll use.
QueryFactory queries = new QueryFactory(mbeanClassName);
queries.buildQueries();
int maxIndex = queries.getSize();
int minIndex = 1;
// Create a reference Set<ObjectName> to check later on
// the queryNames() results
Set<ObjectName> referenceNameSet = new HashSet<ObjectName>();
referenceNameSet.add(on);
// Create a reference Set<ObjectInstance> to check later on
// the queryMBeans() results
ObjectInstance oi = new ObjectInstance(on, mbeanClassName);
Set<ObjectInstance> referenceInstanceSet = new HashSet<ObjectInstance>();
referenceInstanceSet.add(oi);
// Perform the queryNames and queryMBeans requests
for (int i = minIndex; i <= maxIndex; i++) {
QueryExp query = queries.getQuery(i);
System.out.println("----");
System.out.println("SupportedQueryTypesTest::run: Query # " + i);
System.out.println("query " + query);
errorCount += doQueryNames(query, referenceNameSet);
errorCount += doQueryMBeans(query, referenceInstanceSet);
}
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
} finally {
// Do unregister the MBean
try {
if (mbsc.isRegistered(on)) {
mbsc.unregisterMBean(on);
}
if (mbsc.isRegistered(serverDelegateObjectName)) {
mbsc.unregisterMBean(serverDelegateObjectName);
}
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
}
try {
// Close JMX Connector Client
cc.close();
// Stop connertor server
cs.stop();
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
}
}
System.out.println("");
System.out.println("SupportedQueryTypesTest::run: Done");
// Handle result
if (errorCount == 0) {
System.out.println("SupportedQueryTypesTest::run: (OK)");
} else {
String message = "SupportedQueryTypesTest::run: (ERROR) Got " + +errorCount + " error(s)";
System.out.println(message);
throw new RuntimeException(message);
}
}
use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class SameObjectTwoNamesTest method main.
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");
}
Aggregations