Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jstatd/RemoteHostImpl.java
38918 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstatd;2627import java.util.*;28import java.nio.*;29import java.io.*;30import java.net.*;31import java.rmi.*;32import java.rmi.server.*;33import sun.jvmstat.monitor.*;34import sun.jvmstat.monitor.event.*;35import sun.jvmstat.monitor.remote.*;3637/**38* Concrete implementation of the RemoteHost interface for the HotSpot39* PerfData <em>rmi:</em> protocol.40* <p>41* This class provides remote access to the instrumentation exported42* by HotSpot Java Virtual Machines through the PerfData shared memory43* interface.44*45* @author Brian Doherty46* @since 1.547*/48public class RemoteHostImpl implements RemoteHost, HostListener {4950private MonitoredHost monitoredHost;51private Set<Integer> activeVms;5253public RemoteHostImpl() throws MonitorException {54try {55monitoredHost = MonitoredHost.getMonitoredHost("localhost");56} catch (URISyntaxException e) { }5758activeVms = monitoredHost.activeVms();59monitoredHost.addHostListener(this);60}6162public RemoteVm attachVm(int lvmid, String mode)63throws RemoteException, MonitorException {64Integer v = new Integer(lvmid);65RemoteVm stub = null;66StringBuffer sb = new StringBuffer();6768sb.append("local://").append(lvmid).append("@localhost");69if (mode != null) {70sb.append("?mode=" + mode);71}7273String vmidStr = sb.toString();7475try {76VmIdentifier vmid = new VmIdentifier(vmidStr);77MonitoredVm mvm = monitoredHost.getMonitoredVm(vmid);78RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm);79stub = (RemoteVm) UnicastRemoteObject.exportObject(rvm, 0);80}81catch (URISyntaxException e) {82throw new RuntimeException("Malformed VmIdentifier URI: "83+ vmidStr, e);84}85return stub;86}8788public void detachVm(RemoteVm rvm) throws RemoteException {89rvm.detach();90}9192public int[] activeVms() throws MonitorException {93Object[] vms = null;94int[] vmids = null;9596vms = monitoredHost.activeVms().toArray();97vmids = new int[vms.length];9899for (int i = 0; i < vmids.length; i++) {100vmids[i] = ((Integer)vms[i]).intValue();101}102return vmids;103}104105public void vmStatusChanged(VmStatusChangeEvent ev) {106synchronized(this.activeVms) {107activeVms.retainAll(ev.getActive());108}109}110111public void disconnected(HostEvent ev) {112// we only monitor the local host, so this event shouldn't occur.113}114}115116117