Package com.sun.tools.attach

Examples of com.sun.tools.attach.VirtualMachine


         log.entering(className, "start");
      }

      // Find WebSphere Liberty Profile VMs by looking for ws-launch.jar and the name of the server
      String vmid;
      VirtualMachine wlpvm = null;
      String serviceURL = null;

      try {
         vmid = findVirtualMachineIdByName(containerConfiguration.getServerName());
         // If it has already been started, throw exception unless we explicitly allow connecting to a running server
View Full Code Here


            return null;
        }

        JMXServiceURL url;
        try {
            VirtualMachine vm = attachToVirtualMachine(process);

            if (vm == null) {
                return null;
            }

            String jmxConnectorAddress = getJmxConnectorAddress(vm);

            try {
                vm.detach();
            } catch (Exception e) {
                // We already succeeded in obtaining the connector address, so just log this, rather than throwing an exception.
                LOG.error("Failed to detach from JVM [" + vm + "].", e);
            }
View Full Code Here

        return url;
    }

    private static VirtualMachine attachToVirtualMachine(ProcessInfo process) throws AttachNotSupportedException,
        IOException {
        VirtualMachine vm = null;
        List<VirtualMachineDescriptor> vmDescriptors = VirtualMachine.list();
        for (VirtualMachineDescriptor vmDescriptor : vmDescriptors) {
            if (Long.valueOf(vmDescriptor.id()) == process.getPid()) {
                String vmUserName = process.getCredentialsName().getUser();
                String agentUserName = System.getProperty("user.name");
View Full Code Here

    // Attach to pid and perform a thread dump
    private static void runThreadDump(String pid, String args[])
            throws Exception
    {
        VirtualMachine vm = null;
        PrintStream originalErr = System.err;
       
        try
        {
            // Work around the swallowed error when running on Linux
            // which complains windows attacher could not be found
            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();
    }
View Full Code Here


            File bytemanJar = new File(bytemanLib, BytemanConfiguration.BYTEMAN_JAR);
            GenerateScriptUtil.copy(bytemanInputJar, new FileOutputStream(bytemanJar));

            VirtualMachine vm = VirtualMachine.attach(pid);
            String agentProperties = config.agentProperties();
            vm.loadAgent(bytemanJar.getAbsolutePath(), "listener:true,port:" + config.clientAgentPort() + (agentProperties != null ? ",prop:" + agentProperties : ""));
            vm.detach();
        } catch (IOException e) {
            throw new RuntimeException("Could not write byteman.jar to disk", e);
        } catch (Exception e) {
            throw new RuntimeException("Could not install byteman agent", e);
        }
View Full Code Here

            throw new AssertionError(e);
        }
    }

    private static JMXServiceURL getLocalConnectorAddress(String id, boolean startAgent) {
        VirtualMachine vm = null;
        try {
            vm = VirtualMachine.attach(id);
            String connectorAddr = vm.getAgentProperties().getProperty(PROP_LOCAL_CONNECTOR_ADDRESS);
            if (connectorAddr == null && startAgent) {
                final String agent = Paths.get(vm.getSystemProperties().getProperty(PROP_JAVA_HOME)).resolve(MANAGEMENT_AGENT).toString();
                vm.loadAgent(agent);
                connectorAddr = vm.getAgentProperties().getProperty(PROP_LOCAL_CONNECTOR_ADDRESS);
            }
            final JMXServiceURL url = connectorAddr != null ? new JMXServiceURL(connectorAddr) : null;
            vm.detach();
            return url;
        } catch (AttachNotSupportedException e) {
            throw new UnsupportedOperationException(e);
        } catch (Exception e) {
            try {
                if (vm != null)
                    vm.detach();
            } catch (IOException ex) {
                e.addSuppressed(ex);
            }
            throw e instanceof RuntimeException ? (RuntimeException)e : new RuntimeException(e);
        }
View Full Code Here

            File bytemanJar = new File(bytemanLib, BytemanConfiguration.BYTEMAN_JAR);

            GenerateScriptUtil.copy(bytemanInputJar, new FileOutputStream(bytemanJar));

            VirtualMachine vm = VirtualMachine.attach(pid);
            String agentProperties = config.agentProperties();
            vm.loadAgent(bytemanJar.getAbsolutePath(), "listener:true,port:" + config.containerAgentPort() + (agentProperties != null ? ",prop:" + agentProperties : ""));
            vm.detach();
        } catch (IOException e) {
            throw new RuntimeException("Could not write byteman.jar to disk", e);
        } catch (Exception e) {
            throw new RuntimeException("Could not install byteman agent", e);
        }
View Full Code Here

                Integer integer = Integer.valueOf(virtualmachinedescriptor.id());
                if (!map.containsKey(integer)) {
                    boolean flag = false;
                    String s = null;
                    try {
                        VirtualMachine virtualmachine = VirtualMachine.attach(virtualmachinedescriptor);
                        flag = true;
                        Properties properties = virtualmachine.getAgentProperties();
                        s = (String) properties.get("com.sun.management.jmxremote.localConnectorAddress");
                        virtualmachine.detach();
                    }
                    catch (AttachNotSupportedException attachnotsupportedexception) {
                    }
                    catch (IOException ioexception) {
                    }
View Full Code Here

            throw new IOException((new StringBuilder()).
                append("This virtual machine \"").
                append(lvm.getVmid()).append("\" does not support dynamic attach.").toString());


        VirtualMachine virtualmachine = null;
        String s = String.valueOf(lvm.getVmid());
        try {
            virtualmachine = VirtualMachine.attach(s);
        }
        catch (AttachNotSupportedException attachnotsupportedexception) {
            IOException ioexception = new IOException(attachnotsupportedexception.getMessage());
            ioexception.initCause(attachnotsupportedexception);
            throw ioexception;
        }
        String s1 = virtualmachine.getSystemProperties().getProperty("java.home");
        String s2 = (new StringBuilder()).append(s1).append(File.separator).append("jre").append(File.separator).append("lib").append(File.separator).append("management-agent.jar").toString();
        File file = new File(s2);
        if (!file.exists()) {
            s2 = (new StringBuilder()).append(s1).append(File.separator).append("lib").append(File.separator).append("management-agent.jar").toString();
            file = new File(s2);
            if (!file.exists())
                throw new IOException("Management agent not found");
        }
        s2 = file.getCanonicalPath();
        try {
            virtualmachine.loadAgent(s2, "com.sun.management.jmxremote");
        }
        catch (AgentLoadException agentloadexception) {
            IOException ioexception1 = new IOException(agentloadexception.getMessage());
            ioexception1.initCause(agentloadexception);
            throw ioexception1;
        }
        catch (AgentInitializationException agentinitializationexception) {
            IOException ioexception2 = new IOException(agentinitializationexception.getMessage());
            ioexception2.initCause(agentinitializationexception);
            throw ioexception2;
        }
        Properties properties = virtualmachine.getAgentProperties();
        lvm.setConnectorAddress((String) properties.get("com.sun.management.jmxremote.localConnectorAddress"));
        virtualmachine.detach();
    }
View Full Code Here

                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
                    }
View Full Code Here

TOP

Related Classes of com.sun.tools.attach.VirtualMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.