use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class RMIConnectorLogAttributesTest method connectToServer.
private JMXConnector connectToServer(JMXConnectorServer server) throws IOException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException {
JMXServiceURL url = server.getAddress();
Map<String, Object> env = new HashMap<String, Object>();
JMXConnector connector = JMXConnectorFactory.connect(url, env);
System.out.println("DEBUG: Client connected to RMI at: " + url);
return connector;
}
use of javax.management.remote.JMXConnector 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.JMXConnector 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.JMXConnector 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.JMXConnector in project symmetric-ds by JumpMind.
the class JmxCommand method execute.
protected <T> T execute(IJmxTemplate<T> template) throws Exception {
String host = "localhost";
String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + System.getProperty("jmx.agent.port", "31418") + "/jmxrmi";
JMXServiceURL serviceUrl = new JMXServiceURL(url);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
TypedProperties properties = getTypedProperties();
String engineName = properties.get(ParameterConstants.ENGINE_NAME, "unknown");
try {
MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
return template.execute(engineName, mbeanConn);
} finally {
jmxConnector.close();
}
}
Aggregations