jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/LocalVirtualMachine.java
author lana
Thu, 11 May 2017 18:11:13 +0000
changeset 45111 6aa4e0cafe2e
parent 43494 11801b2ff456
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 14342
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.attach.VirtualMachine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.attach.VirtualMachineDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.attach.AttachNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
43494
11801b2ff456 8173608: Separate JDK management agent from java.management module
mchung
parents: 25859
diff changeset
    36
import jdk.internal.agent.ConnectorAddressLink;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.jvmstat.monitor.HostIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.jvmstat.monitor.MonitoredHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.jvmstat.monitor.MonitoredVm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.jvmstat.monitor.MonitoredVmUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.jvmstat.monitor.MonitorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.jvmstat.monitor.VmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class LocalVirtualMachine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private String address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private String commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private String displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private boolean isAttachSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public LocalVirtualMachine(int vmid, String commandLine, boolean canAttach, String connectorAddress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this.vmid = vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this.commandLine = commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.address = connectorAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.isAttachSupported = canAttach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.displayName = getDisplayName(commandLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static String getDisplayName(String commandLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // trim the pathname of jar file if it's a jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        String[] res = commandLine.split(" ", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (res[0].endsWith(".jar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
           File jarfile = new File(res[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
           String displayName = jarfile.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
           if (res.length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
               displayName += " " + res[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
           return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public int vmid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public boolean isManageable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return (address != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public boolean isAttachable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return isAttachSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public void startManagementAgent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (address != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // already started
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (!isAttachable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new IOException("This virtual machine \"" + vmid +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                "\" does not support dynamic attach.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        loadManagementAgent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // fails to load or start the management agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (address == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            // should never reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IOException("Fails to find connector address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public String connectorAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // return null if not available or no JMX agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public String displayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // This method returns the list of all virtual machines currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // running on the machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static Map<Integer, LocalVirtualMachine> getAllVirtualMachines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Map<Integer, LocalVirtualMachine> map =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            new HashMap<Integer, LocalVirtualMachine>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        getMonitoredVMs(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        getAttachableVMs(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        MonitoredHost host;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 10419
diff changeset
   129
        Set<Integer> vms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            vms = host.activeVms();
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   133
        } catch (java.net.URISyntaxException | MonitorException x) {
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   134
            throw new InternalError(x.getMessage(), x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        for (Object vmid: vms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (vmid instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                int pid = ((Integer) vmid).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                String name = vmid.toString(); // default to pid if name not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                     MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                     // use the command line as the display name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                     name =  MonitoredVmUtil.commandLine(mvm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                     attachable = MonitoredVmUtil.isAttachable(mvm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                     address = ConnectorAddressLink.importFrom(pid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                     mvm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                map.put((Integer) vmid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                        new LocalVirtualMachine(pid, name, attachable, address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        "com.sun.management.jmxremote.localConnectorAddress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        List<VirtualMachineDescriptor> vms = VirtualMachine.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        for (VirtualMachineDescriptor vmd : vms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                Integer vmid = Integer.valueOf(vmd.id());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                if (!map.containsKey(vmid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        VirtualMachine vm = VirtualMachine.attach(vmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        attachable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        // not attachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    map.put(vmid, new LocalVirtualMachine(vmid.intValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                                          vmd.displayName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                                          attachable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                          address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                // do not support vmid different than pid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public static LocalVirtualMachine getLocalVirtualMachine(int vmid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Map<Integer, LocalVirtualMachine> map = getAllVirtualMachines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        LocalVirtualMachine lvm = map.get(vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (lvm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // Check if the VM is attachable but not included in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            // if it's running with a different security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // For example, Windows services running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // local SYSTEM account are attachable if you have Adminstrator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // privileges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            String name = String.valueOf(vmid); // default display name to pid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                VirtualMachine vm = VirtualMachine.attach(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                attachable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                lvm = new LocalVirtualMachine(vmid, name, attachable, address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                // not attachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return lvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    // load the management agent into the target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private void loadManagementAgent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        VirtualMachine vm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        String name = String.valueOf(vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            vm = VirtualMachine.attach(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            IOException ioe = new IOException(x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            ioe.initCause(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 14342
diff changeset
   237
        vm.startLocalManagementAgent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // get the connector address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}