0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.tools.jstatd;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.nio.*;
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.server.*;
0N/Aimport sun.jvmstat.monitor.*;
0N/Aimport sun.jvmstat.monitor.event.*;
0N/Aimport sun.jvmstat.monitor.remote.*;
0N/A
0N/A/**
0N/A * Concrete implementation of the RemoteHost interface for the HotSpot
0N/A * PerfData <em>rmi:</em> protocol.
0N/A * <p>
0N/A * This class provides remote access to the instrumentation exported
0N/A * by HotSpot Java Virtual Machines through the PerfData shared memory
0N/A * interface.
0N/A *
0N/A * @author Brian Doherty
0N/A * @since 1.5
0N/A */
0N/Apublic class RemoteHostImpl implements RemoteHost, HostListener {
0N/A
0N/A private MonitoredHost monitoredHost;
0N/A private Set<Integer> activeVms;
0N/A
0N/A public RemoteHostImpl() throws MonitorException {
0N/A try {
0N/A monitoredHost = MonitoredHost.getMonitoredHost("localhost");
0N/A } catch (URISyntaxException e) { }
0N/A
0N/A activeVms = monitoredHost.activeVms();
0N/A monitoredHost.addHostListener(this);
0N/A }
0N/A
0N/A public RemoteVm attachVm(int lvmid, String mode)
0N/A throws RemoteException, MonitorException {
0N/A Integer v = new Integer(lvmid);
0N/A RemoteVm stub = null;
0N/A StringBuffer sb = new StringBuffer();
0N/A
0N/A sb.append("local://").append(lvmid).append("@localhost");
0N/A if (mode != null) {
0N/A sb.append("?mode=" + mode);
0N/A }
0N/A
0N/A String vmidStr = sb.toString();
0N/A
0N/A try {
0N/A VmIdentifier vmid = new VmIdentifier(vmidStr);
0N/A MonitoredVm mvm = monitoredHost.getMonitoredVm(vmid);
0N/A RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm);
0N/A stub = (RemoteVm) UnicastRemoteObject.exportObject(rvm, 0);
0N/A }
0N/A catch (URISyntaxException e) {
0N/A throw new RuntimeException("Malformed VmIdentifier URI: "
0N/A + vmidStr, e);
0N/A }
0N/A return stub;
0N/A }
0N/A
0N/A public void detachVm(RemoteVm rvm) throws RemoteException {
0N/A rvm.detach();
0N/A }
0N/A
0N/A public int[] activeVms() throws MonitorException {
0N/A Object[] vms = null;
0N/A int[] vmids = null;
0N/A
0N/A vms = monitoredHost.activeVms().toArray();
0N/A vmids = new int[vms.length];
0N/A
0N/A for (int i = 0; i < vmids.length; i++) {
0N/A vmids[i] = ((Integer)vms[i]).intValue();
0N/A }
0N/A return vmids;
0N/A }
0N/A
0N/A public void vmStatusChanged(VmStatusChangeEvent ev) {
0N/A synchronized(this.activeVms) {
0N/A activeVms.retainAll(ev.getActive());
0N/A }
0N/A }
0N/A
0N/A public void disconnected(HostEvent ev) {
0N/A // we only monitor the local host, so this event shouldn't occur.
0N/A }
0N/A}