jdk/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java
changeset 24870 5d567113d043
parent 14342 8435a30053c1
equal deleted inserted replaced
24869:6cdd5aa7e259 24870:5d567113d043
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    30 import java.io.File;
    30 import java.io.File;
    31 
    31 
    32 // Sun specific
    32 // Sun specific
    33 import com.sun.tools.attach.VirtualMachine;
    33 import com.sun.tools.attach.VirtualMachine;
    34 import com.sun.tools.attach.VirtualMachineDescriptor;
    34 import com.sun.tools.attach.VirtualMachineDescriptor;
    35 import com.sun.tools.attach.AgentInitializationException;
       
    36 import com.sun.tools.attach.AgentLoadException;
       
    37 import com.sun.tools.attach.AttachNotSupportedException;
    35 import com.sun.tools.attach.AttachNotSupportedException;
    38 
    36 
    39 // Sun private
    37 // Sun private
    40 import sun.management.ConnectorAddressLink;
    38 import sun.management.ConnectorAddressLink;
    41 import sun.jvmstat.monitor.HostIdentifier;
    39 import sun.jvmstat.monitor.HostIdentifier;
   236             IOException ioe = new IOException(x.getMessage());
   234             IOException ioe = new IOException(x.getMessage());
   237             ioe.initCause(x);
   235             ioe.initCause(x);
   238             throw ioe;
   236             throw ioe;
   239         }
   237         }
   240 
   238 
   241         String home = vm.getSystemProperties().getProperty("java.home");
   239         vm.startLocalManagementAgent();
   242 
       
   243         // Normally in ${java.home}/jre/lib/management-agent.jar but might
       
   244         // be in ${java.home}/lib in build environments.
       
   245 
       
   246         String agent = home + File.separator + "jre" + File.separator +
       
   247                            "lib" + File.separator + "management-agent.jar";
       
   248         File f = new File(agent);
       
   249         if (!f.exists()) {
       
   250             agent = home + File.separator +  "lib" + File.separator +
       
   251                         "management-agent.jar";
       
   252             f = new File(agent);
       
   253             if (!f.exists()) {
       
   254                 throw new IOException("Management agent not found");
       
   255             }
       
   256         }
       
   257 
       
   258         agent = f.getCanonicalPath();
       
   259         try {
       
   260             vm.loadAgent(agent, "com.sun.management.jmxremote");
       
   261         } catch (AgentLoadException x) {
       
   262             IOException ioe = new IOException(x.getMessage());
       
   263             ioe.initCause(x);
       
   264             throw ioe;
       
   265         } catch (AgentInitializationException x) {
       
   266             IOException ioe = new IOException(x.getMessage());
       
   267             ioe.initCause(x);
       
   268             throw ioe;
       
   269         }
       
   270 
   240 
   271         // get the connector address
   241         // get the connector address
   272         Properties agentProps = vm.getAgentProperties();
   242         Properties agentProps = vm.getAgentProperties();
   273         address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
   243         address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
   274 
   244