Search in sources :

Example 6 with AttachOperationFailedException

use of com.sun.tools.attach.AttachOperationFailedException in project jdk8u_jdk by JetBrains.

the class LinuxVirtualMachine method execute.

/**
     * Execute the given command in the target VM.
     */
InputStream execute(String cmd, Object... args) throws AgentLoadException, IOException {
    // includes null
    assert args.length <= 3;
    // did we detach?
    String p;
    synchronized (this) {
        if (this.path == null) {
            throw new IOException("Detached from target VM");
        }
        p = this.path;
    }
    // create UNIX socket
    int s = socket();
    // connect to target VM
    try {
        connect(s, p);
    } catch (IOException x) {
        close(s);
        throw x;
    }
    IOException ioe = null;
    // <ver> <cmd> <args...>
    try {
        writeString(s, PROTOCOL_VERSION);
        writeString(s, cmd);
        for (int i = 0; i < 3; i++) {
            if (i < args.length && args[i] != null) {
                writeString(s, (String) args[i]);
            } else {
                writeString(s, "");
            }
        }
    } catch (IOException x) {
        ioe = x;
    }
    // Create an input stream to read reply
    SocketInputStream sis = new SocketInputStream(s);
    // Read the command completion status
    int completionStatus;
    try {
        completionStatus = readInt(sis);
    } catch (IOException x) {
        sis.close();
        if (ioe != null) {
            throw ioe;
        } else {
            throw x;
        }
    }
    if (completionStatus != 0) {
        // read from the stream and use that as the error message
        String message = readErrorMessage(sis);
        sis.close();
        // error.
        if (completionStatus == ATTACH_ERROR_BADVERSION) {
            throw new IOException("Protocol mismatch with target VM");
        }
        // thrown.
        if (cmd.equals("load")) {
            throw new AgentLoadException("Failed to load agent library");
        } else {
            if (message == null) {
                throw new AttachOperationFailedException("Command failed in target VM");
            } else {
                throw new AttachOperationFailedException(message);
            }
        }
    }
    // Return the input stream so that the command output can be read
    return sis;
}
Also used : AttachOperationFailedException(com.sun.tools.attach.AttachOperationFailedException) AgentLoadException(com.sun.tools.attach.AgentLoadException) IOException(java.io.IOException)

Aggregations

AttachOperationFailedException (com.sun.tools.attach.AttachOperationFailedException)6 AgentLoadException (com.sun.tools.attach.AgentLoadException)4 IOException (java.io.IOException)4 Properties (java.util.Properties)2 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)1 VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MonitorException (sun.jvmstat.monitor.MonitorException)1