use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class RMIExitTest method test.
private static void test() {
try {
JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer server;
JMXServiceURL addr;
JMXConnector client;
MBeanServerConnection mserver;
final ObjectName delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
final NotificationListener dummyListener = new NotificationListener() {
public void handleNotification(Notification n, Object o) {
// do nothing
return;
}
};
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
server.start();
addr = server.getAddress();
client = JMXConnectorFactory.newJMXConnector(addr, null);
client.connect(null);
mserver = client.getMBeanServerConnection();
String s1 = "1";
String s2 = "2";
String s3 = "3";
mserver.addNotificationListener(delegateName, dummyListener, null, s1);
mserver.addNotificationListener(delegateName, dummyListener, null, s2);
mserver.addNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s2);
mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
client.close();
server.stop();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
System.exit(1);
}
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class RMIDownloadTest method testWithException.
private static void testWithException(boolean send) throws Exception {
ClassLoader zoobyCL = new ZoobyClassLoader();
Class<?> zoobyClass = Class.forName("Zooby", false, zoobyCL);
Object zooby = zoobyClass.newInstance();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, pmbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
Object rzooby;
if (send) {
System.out.println("Sending object...");
mbsc.setAttribute(getSetName, new Attribute("It", zooby));
rzooby = getSetInstance.getIt();
} else {
System.out.println("Receiving object...");
getSetInstance.setIt(zooby);
rzooby = mbsc.getAttribute(getSetName, "It");
}
if (!rzooby.getClass().getName().equals("Zooby")) {
throw new Exception("FAILED: remote object is not a Zooby");
}
if (rzooby.getClass().getClassLoader() == zooby.getClass().getClassLoader()) {
throw new Exception("FAILED: same class loader: " + zooby.getClass().getClassLoader());
}
cc.close();
cs.stop();
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class MXBeanExceptionHandlingTest method run.
public void run(Map<String, Object> args) {
System.out.println("MXBeanExceptionHandlingTest::run: Start");
int errorCount = 0;
try {
parseArgs(args);
notifList = new ArrayBlockingQueue<Notification>(numOfNotifications);
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println("Add me as notification listener");
mbsc.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, null, null);
System.out.println("---- OK\n");
// ----
System.out.println("Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi");
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println("---- OK\n");
// ----
System.out.println("Call method throwException on our MXBean");
try {
mbsc.invoke(objName, "throwException", null, null);
errorCount++;
System.out.println("(ERROR) Did not get awaited MBeanException");
} catch (MBeanException mbe) {
System.out.println("(OK) Got awaited MBeanException");
Throwable cause = mbe.getCause();
if (cause instanceof java.lang.Exception) {
System.out.println("(OK) Cause is of the right class");
String mess = cause.getMessage();
if (mess.equals(Basic.EXCEPTION_MESSAGE)) {
System.out.println("(OK) Cause message is fine");
} else {
errorCount++;
System.out.println("(ERROR) Cause has message " + cause.getMessage() + " as we expect " + Basic.EXCEPTION_MESSAGE);
}
} else {
errorCount++;
System.out.println("(ERROR) Cause is of class " + cause.getClass().getName() + " as we expect java.lang.Exception");
}
} catch (Exception e) {
errorCount++;
System.out.println("(ERROR) Did not get awaited MBeanException but " + e);
Utils.printThrowable(e, true);
}
System.out.println("---- DONE\n");
// ----
System.out.println("Call method throwError on our MXBean");
try {
mbsc.invoke(objName, "throwError", null, null);
errorCount++;
System.out.println("(ERROR) Did not get awaited RuntimeErrorException");
} catch (RuntimeErrorException ree) {
System.out.println("(OK) Got awaited RuntimeErrorException");
Throwable cause = ree.getCause();
if (cause instanceof java.lang.InternalError) {
System.out.println("(OK) Cause is of the right class");
String mess = cause.getMessage();
if (mess.equals(Basic.EXCEPTION_MESSAGE)) {
System.out.println("(OK) Cause message is fine");
} else {
errorCount++;
System.out.println("(ERROR) Cause has message " + cause.getMessage() + " as we expect " + Basic.EXCEPTION_MESSAGE);
}
} else {
errorCount++;
System.out.println("(ERROR) Cause is of class " + cause.getClass().getName() + " as we expect java.lang.InternalError");
}
} catch (Exception e) {
errorCount++;
System.out.println("(ERROR) Did not get awaited RuntimeErrorException but " + e);
Utils.printThrowable(e, true);
}
System.out.println("---- DONE\n");
// ----
System.out.println("Unregister the MBean");
mbsc.unregisterMBean(objName);
System.out.println("---- OK\n");
Thread.sleep(timeForNotificationInSeconds * 1000);
int numOfReceivedNotif = notifList.size();
if (numOfReceivedNotif == numOfNotifications) {
System.out.println("(OK) We received " + numOfNotifications + " Notifications");
} else {
errorCount++;
System.out.println("(ERROR) We received " + numOfReceivedNotif + " Notifications in place of " + numOfNotifications);
}
} catch (Exception e) {
Utils.printThrowable(e, true);
throw new RuntimeException(e);
}
if (errorCount == 0) {
System.out.println("MXBeanExceptionHandlingTest::run: Done without any error");
} else {
System.out.println("MXBeanExceptionHandlingTest::run: Done with " + errorCount + " error(s)");
throw new RuntimeException("errorCount = " + errorCount);
}
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class UnserializableTargetObjectTest method main.
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("a:b=c");
Resource resource1 = new Resource();
Resource resource2 = new Resource();
Resource resource3 = new Resource();
Method operationMethod = Resource.class.getMethod("operation");
Method getCountMethod = Resource.class.getMethod("getCount");
Method setCountMethod = Resource.class.getMethod("setCount", int.class);
Descriptor operationDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "operation", resource1 });
Descriptor getCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "getCount", resource2 });
Descriptor setCountDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "targetObject" }, new Object[] { "operation", "setCount", resource2 });
Descriptor countDescriptor = new DescriptorSupport(new String[] { "descriptorType", "name", "getMethod", "setMethod" }, new Object[] { "attribute", "Count", "getCount", "setCount" });
ModelMBeanOperationInfo operationInfo = new ModelMBeanOperationInfo("operation description", operationMethod, operationDescriptor);
ModelMBeanOperationInfo getCountInfo = new ModelMBeanOperationInfo("getCount description", getCountMethod, getCountDescriptor);
ModelMBeanOperationInfo setCountInfo = new ModelMBeanOperationInfo("setCount description", setCountMethod, setCountDescriptor);
ModelMBeanAttributeInfo countInfo = new ModelMBeanAttributeInfo("Count", "Count description", getCountMethod, setCountMethod, countDescriptor);
ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "ModelMBean to test targetObject", new ModelMBeanAttributeInfo[] { countInfo }, // no constructors
null, new ModelMBeanOperationInfo[] { operationInfo, getCountInfo, setCountInfo }, // no notifications
null);
ModelMBean mmb = new RequiredModelMBean(mmbi);
mmb.setManagedResource(resource3, "ObjectReference");
mbs.registerMBean(mmb, name);
mbs.invoke(name, "operation", null, null);
mbs.setAttribute(name, new Attribute("Count", 53));
if (resource1.operationCount != 1)
throw new Exception("operationCount: " + resource1.operationCount);
if (resource2.count != 53)
throw new Exception("count: " + resource2.count);
int got = (Integer) mbs.getAttribute(name, "Count");
if (got != 53)
throw new Exception("got count: " + got);
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
// Above gets NotSerializableException if resource included in
// serialized form
cc.close();
cs.stop();
System.out.println("TEST PASSED");
}
use of javax.management.remote.JMXConnectorServer 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);
}
}
Aggregations