本文整理匯總了Java中com.sun.tools.attach.VirtualMachine.startManagementAgent方法的典型用法代碼示例。如果您正苦於以下問題:Java VirtualMachine.startManagementAgent方法的具體用法?Java VirtualMachine.startManagementAgent怎麽用?Java VirtualMachine.startManagementAgent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.tools.attach.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.startManagementAgent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: basicTests
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
private static void basicTests(VirtualMachine vm) throws Exception {
// Try calling with null argument
boolean exception = false;
try {
vm.startManagementAgent(null);
} catch (NullPointerException e) {
exception = true;
}
if (!exception) {
throw new Exception("startManagementAgent(null) should throw NPE");
}
// Try calling with a property value with a space in it
Properties p = new Properties();
File f = new File("file with space");
try (FileWriter fw = new FileWriter(f)) {
fw.write("com.sun.management.jmxremote.port=apa");
}
p.put("com.sun.management.config.file", f.getAbsolutePath());
try {
vm.startManagementAgent(p);
} catch(AttachOperationFailedException ex) {
// We expect parsing of "apa" above to fail, but if the file path
// can't be read we get a different exception message
if (!ex.getMessage().contains("java.lang.NumberFormatException")) {
throw ex;
}
}
}
示例2: testRemoteAgent
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
public static void testRemoteAgent(VirtualMachine vm) throws Exception {
int port = Utils.getFreePort();
// try to connect - should fail
tryConnect(port, false);
// start agent
System.out.println("Starting agent on port: " + port);
Properties mgmtProps = new Properties();
mgmtProps.put("com.sun.management.jmxremote.port", port);
mgmtProps.put("com.sun.management.jmxremote.authenticate", "false");
mgmtProps.put("com.sun.management.jmxremote.ssl", "false");
vm.startManagementAgent(mgmtProps);
// try to connect - should work
tryConnect(port, true);
// try to start again - should fail
boolean exception = false;
try {
vm.startManagementAgent(mgmtProps);
} catch(AttachOperationFailedException ex) {
// expected
exception = true;
}
if (!exception) {
throw new Exception("Expected the second call to vm.startManagementAgent() to fail");
}
}
示例3: basicTests
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
private static void basicTests(VirtualMachine vm) throws Exception {
// Try calling with null argument
boolean exception = false;
try {
System.out.println("Starting management agent with null");
vm.startManagementAgent(null);
} catch (NullPointerException e) {
exception = true;
}
if (!exception) {
throw new Exception("startManagementAgent(null) should throw NPE");
}
// Try calling with a property value with a space in it
Properties p = new Properties();
File f = new File("file with space");
try (FileWriter fw = new FileWriter(f)) {
fw.write("com.sun.management.jmxremote.port=apa");
}
p.put("com.sun.management.config.file", f.getAbsolutePath());
try {
System.out.println("Starting management agent with bogus port");
vm.startManagementAgent(p);
} catch(AttachOperationFailedException ex) {
// We expect parsing of "apa" above to fail, but if the file path
// can't be read we get a different exception message
if (!ex.getMessage().contains("Invalid com.sun.management.jmxremote.port number")) {
throw ex;
}
ex.printStackTrace(System.err);
} catch (Throwable t) {
t.printStackTrace(System.err);
throw t;
}
}
示例4: testRemoteAgent
import com.sun.tools.attach.VirtualMachine; //導入方法依賴的package包/類
public static void testRemoteAgent(VirtualMachine vm) throws Exception {
int port = Utils.getFreePort();
// try to connect - should fail
tryConnect(port, false);
// start agent
System.out.println("Starting agent on port: " + port);
Properties mgmtProps = new Properties();
mgmtProps.put("com.sun.management.jmxremote.port", port);
mgmtProps.put("com.sun.management.jmxremote.authenticate", "false");
mgmtProps.put("com.sun.management.jmxremote.ssl", "false");
System.err.println("Starting management agent ...");
vm.startManagementAgent(mgmtProps);
System.err.println("Started");
// try to connect - should work
tryConnect(port, true);
// try to start again - should fail
boolean exception = false;
try {
System.err.println("Starting management agent second time ...");
vm.startManagementAgent(mgmtProps);
System.err.println("Started");
} catch(AttachOperationFailedException ex) {
// expected
System.err.println("Got expected exception: " + ex.getMessage());
exception = true;
}
if (!exception) {
throw new Exception("Expected the second call to vm.startManagementAgent() to fail");
}
}