當前位置: 首頁>>代碼示例>>Java>>正文


Java VirtualMachine.startManagementAgent方法代碼示例

本文整理匯總了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;
            }
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:31,代碼來源:StartManagementAgent.java

示例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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:StartManagementAgent.java

示例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;
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:StartManagementAgent.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:StartManagementAgent.java


注:本文中的com.sun.tools.attach.VirtualMachine.startManagementAgent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。