jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/LocalVirtualMachine.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 25859 3317bb8137f4
child 43494 11801b2ff456
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
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
// Sun specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.attach.VirtualMachine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.attach.VirtualMachineDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.attach.AttachNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// Sun private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.management.ConnectorAddressLink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.jvmstat.monitor.HostIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.jvmstat.monitor.MonitoredHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.jvmstat.monitor.MonitoredVm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.jvmstat.monitor.MonitoredVmUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.jvmstat.monitor.MonitorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.jvmstat.monitor.VmIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class LocalVirtualMachine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private String address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private String commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private String displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private int vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean isAttachSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public LocalVirtualMachine(int vmid, String commandLine, boolean canAttach, String connectorAddress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.vmid = vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.commandLine = commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.address = connectorAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.isAttachSupported = canAttach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.displayName = getDisplayName(commandLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static String getDisplayName(String commandLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // trim the pathname of jar file if it's a jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        String[] res = commandLine.split(" ", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (res[0].endsWith(".jar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
           File jarfile = new File(res[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
           String displayName = jarfile.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
           if (res.length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
               displayName += " " + res[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
           return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public int vmid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return vmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public boolean isManageable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return (address != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public boolean isAttachable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return isAttachSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void startManagementAgent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (address != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            // already started
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (!isAttachable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new IOException("This virtual machine \"" + vmid +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                "\" does not support dynamic attach.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        loadManagementAgent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // fails to load or start the management agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (address == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            // should never reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new IOException("Fails to find connector address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public String connectorAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // return null if not available or no JMX agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public String displayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // This method returns the list of all virtual machines currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // running on the machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static Map<Integer, LocalVirtualMachine> getAllVirtualMachines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Map<Integer, LocalVirtualMachine> map =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            new HashMap<Integer, LocalVirtualMachine>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        getMonitoredVMs(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        getAttachableVMs(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        MonitoredHost host;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 10419
diff changeset
   131
        Set<Integer> vms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            vms = host.activeVms();
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   135
        } catch (java.net.URISyntaxException | MonitorException x) {
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   136
            throw new InternalError(x.getMessage(), x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        for (Object vmid: vms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (vmid instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                int pid = ((Integer) vmid).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                String name = vmid.toString(); // default to pid if name not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                     MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                     // use the command line as the display name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                     name =  MonitoredVmUtil.commandLine(mvm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                     attachable = MonitoredVmUtil.isAttachable(mvm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                     address = ConnectorAddressLink.importFrom(pid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     mvm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                     // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                map.put((Integer) vmid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        new LocalVirtualMachine(pid, name, attachable, address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        "com.sun.management.jmxremote.localConnectorAddress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        List<VirtualMachineDescriptor> vms = VirtualMachine.list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        for (VirtualMachineDescriptor vmd : vms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                Integer vmid = Integer.valueOf(vmd.id());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (!map.containsKey(vmid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        VirtualMachine vm = VirtualMachine.attach(vmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        attachable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        // not attachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    map.put(vmid, new LocalVirtualMachine(vmid.intValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                          vmd.displayName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                                          attachable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                          address));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                // do not support vmid different than pid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public static LocalVirtualMachine getLocalVirtualMachine(int vmid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        Map<Integer, LocalVirtualMachine> map = getAllVirtualMachines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        LocalVirtualMachine lvm = map.get(vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (lvm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // Check if the VM is attachable but not included in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // if it's running with a different security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // For example, Windows services running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // local SYSTEM account are attachable if you have Adminstrator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // privileges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            boolean attachable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            String name = String.valueOf(vmid); // default display name to pid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                VirtualMachine vm = VirtualMachine.attach(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                attachable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                lvm = new LocalVirtualMachine(vmid, name, attachable, address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                // not attachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return lvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // load the management agent into the target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private void loadManagementAgent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        VirtualMachine vm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        String name = String.valueOf(vmid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            vm = VirtualMachine.attach(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            IOException ioe = new IOException(x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            ioe.initCause(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 14342
diff changeset
   239
        vm.startLocalManagementAgent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // get the connector address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Properties agentProps = vm.getAgentProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}