4632N/A/*
4632N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/Apackage sun.tools.attach;
4632N/A
4632N/Aimport com.sun.tools.attach.VirtualMachine;
4632N/Aimport com.sun.tools.attach.VirtualMachineDescriptor;
4632N/Aimport com.sun.tools.attach.AttachNotSupportedException;
4632N/Aimport com.sun.tools.attach.spi.AttachProvider;
4632N/A
4632N/Aimport java.io.IOException;
4632N/A
4632N/A/*
4632N/A * An AttachProvider implementation for Bsd that uses a UNIX domain
4632N/A * socket.
4632N/A */
4632N/Apublic class BsdAttachProvider extends HotSpotAttachProvider {
4632N/A
4632N/A // perf counter for the JVM version
4632N/A private static final String JVM_VERSION = "java.property.java.vm.version";
4632N/A
4632N/A public BsdAttachProvider() {
4632N/A }
4632N/A
4632N/A public String name() {
4632N/A return "sun";
4632N/A }
4632N/A
4632N/A public String type() {
4632N/A return "socket";
4632N/A }
4632N/A
4632N/A public VirtualMachine attachVirtualMachine(String vmid)
4632N/A throws AttachNotSupportedException, IOException
4632N/A {
4632N/A checkAttachPermission();
4632N/A
4632N/A // AttachNotSupportedException will be thrown if the target VM can be determined
4632N/A // to be not attachable.
4632N/A testAttachable(vmid);
4632N/A
4632N/A return new BsdVirtualMachine(this, vmid);
4632N/A }
4632N/A
4632N/A public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
4632N/A throws AttachNotSupportedException, IOException
4632N/A {
4632N/A if (vmd.provider() != this) {
4632N/A throw new AttachNotSupportedException("provider mismatch");
4632N/A }
4632N/A // To avoid re-checking if the VM if attachable, we check if the descriptor
4632N/A // is for a hotspot VM - these descriptors are created by the listVirtualMachines
4632N/A // implementation which only returns a list of attachable VMs.
4632N/A if (vmd instanceof HotSpotVirtualMachineDescriptor) {
4632N/A assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
4632N/A checkAttachPermission();
4632N/A return new BsdVirtualMachine(this, vmd.id());
4632N/A } else {
4632N/A return attachVirtualMachine(vmd.id());
4632N/A }
4632N/A }
4632N/A
4632N/A}