Search in sources :

Example 6 with AttachNotSupportedException

use of com.sun.tools.attach.AttachNotSupportedException in project geode by apache.

the class MBeanProcessController method connect.

/**
   * Connects to the JMX agent in the local process.
   * 
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if the JDK management agent cannot be found and loaded
   */
private void connect() throws ConnectionFailedException, IOException {
    try {
        final JMXServiceURL jmxUrl = getJMXServiceURL();
        this.jmxc = JMXConnectorFactory.connect(jmxUrl);
        this.server = this.jmxc.getMBeanServerConnection();
    } catch (AttachNotSupportedException e) {
        throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException)

Example 7 with AttachNotSupportedException

use of com.sun.tools.attach.AttachNotSupportedException in project geode by apache.

the class LocalProcessController method connect.

/**
   * Connects to the JMX agent in the local process.
   * 
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if the JDK management agent cannot be found and loaded
   */
void connect() throws ConnectionFailedException, IOException {
    try {
        final JMXServiceURL jmxUrl = getJMXServiceURL();
        this.jmxc = JMXConnectorFactory.connect(jmxUrl);
        this.server = this.jmxc.getMBeanServerConnection();
    } catch (AttachNotSupportedException e) {
        throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException)

Example 8 with AttachNotSupportedException

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

the class JStack method runThreadDump.

// Attach to pid and perform a thread dump
private static void runThreadDump(String pid, String[] args) throws Exception {
    VirtualMachine vm = null;
    try {
        vm = VirtualMachine.attach(pid);
    } catch (Exception x) {
        String msg = x.getMessage();
        if (msg != null) {
            System.err.println(pid + ": " + msg);
        } else {
            x.printStackTrace();
        }
        if ((x instanceof AttachNotSupportedException) && (loadSAClass() != null)) {
            System.err.println("The -F option can be used when the target " + "process is not responding");
        }
        System.exit(1);
    }
    // Cast to HotSpotVirtualMachine as this is implementation specific
    // method.
    InputStream in = ((HotSpotVirtualMachine) vm).remoteDataDump((Object[]) args);
    // read to EOF and just print output
    byte[] b = new byte[256];
    int n;
    do {
        n = in.read(b);
        if (n > 0) {
            String s = new String(b, 0, n, "UTF-8");
            System.out.print(s);
        }
    } while (n > 0);
    in.close();
    vm.detach();
}
Also used : InputStream(java.io.InputStream) HotSpotVirtualMachine(sun.tools.attach.HotSpotVirtualMachine) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) IOException(java.io.IOException) VirtualMachine(com.sun.tools.attach.VirtualMachine) HotSpotVirtualMachine(sun.tools.attach.HotSpotVirtualMachine)

Example 9 with AttachNotSupportedException

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

the class LocalVirtualMachine method getAttachableVMs.

private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
    List<VirtualMachineDescriptor> vms = VirtualMachine.list();
    for (VirtualMachineDescriptor vmd : vms) {
        try {
            Integer vmid = Integer.valueOf(vmd.id());
            if (!map.containsKey(vmid)) {
                boolean attachable = false;
                String address = null;
                try {
                    VirtualMachine vm = VirtualMachine.attach(vmd);
                    attachable = true;
                    Properties agentProps = vm.getAgentProperties();
                    address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
                    vm.detach();
                } catch (AttachNotSupportedException x) {
                // not attachable
                } catch (IOException x) {
                // ignore
                }
                map.put(vmid, new LocalVirtualMachine(vmid.intValue(), vmd.displayName(), attachable, address));
            }
        } catch (NumberFormatException e) {
        // do not support vmid different than pid
        }
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) VirtualMachine(com.sun.tools.attach.VirtualMachine)

Aggregations

AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)9 VirtualMachine (com.sun.tools.attach.VirtualMachine)6 IOException (java.io.IOException)6 VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 AgentInitializationException (com.sun.tools.attach.AgentInitializationException)1 AgentLoadException (com.sun.tools.attach.AgentLoadException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 MonitoredHost (sun.jvmstat.monitor.MonitoredHost)1 MonitoredVm (sun.jvmstat.monitor.MonitoredVm)1 VmIdentifier (sun.jvmstat.monitor.VmIdentifier)1 HotSpotVirtualMachine (sun.tools.attach.HotSpotVirtualMachine)1