com.sun.tools.attach.AttachOperationFailedException Java Examples

The following examples show how to use com.sun.tools.attach.AttachOperationFailedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartManagementAgent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
 
Example #2
Source File: StartManagementAgent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #3
Source File: StartManagementAgent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
            }
        }
    }
 
Example #4
Source File: StartManagementAgent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #5
Source File: StartManagementAgent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
            }
        }
    }
 
Example #6
Source File: StartManagementAgent.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #7
Source File: StartManagementAgent.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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("NumberFormatException: For input string: \"apa\"")) {
                throw ex;
            }
        }
    }
 
Example #8
Source File: StartManagementAgent.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #9
Source File: StartManagementAgent.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
            }
        }
    }
 
Example #10
Source File: StartManagementAgent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #11
Source File: StartManagementAgent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
            }
        }
    }
 
Example #12
Source File: StartManagementAgent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #13
Source File: StartManagementAgent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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("NumberFormatException: For input string: \"apa\"")) {
                throw ex;
            }
        }
    }
 
Example #14
Source File: JVMOption.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean setFlagAttach(HotSpotVirtualMachine vm, String flagName, String flagValue) throws Exception {
    boolean result;

    try {
        vm.setFlag(flagName, flagValue);
        result = true;
    } catch (AttachOperationFailedException e) {
        result = false;
    }

    return result;
}
 
Example #15
Source File: StartManagementAgent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #16
Source File: StartManagementAgent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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("Invalid com.sun.management.jmxremote.port number")) {
                throw ex;
            }
        }
    }
 
Example #17
Source File: StartManagementAgent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #18
Source File: StartManagementAgent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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("NumberFormatException: For input string: \"apa\"")) {
                throw ex;
            }
        }
    }
 
Example #19
Source File: StartManagementAgent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #20
Source File: StartManagementAgent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
            }
        }
    }
 
Example #21
Source File: StartManagementAgent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #22
Source File: StartManagementAgent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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("NumberFormatException: For input string: \"apa\"")) {
                throw ex;
            }
        }
    }
 
Example #23
Source File: StartManagementAgent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}