author | erikj |
Wed, 07 Mar 2018 13:26:15 -0800 | |
changeset 49357 | aaedb8343784 |
parent 47216 | 71c04702a3d5 |
child 54277 | f283f6871336 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.tools.jstatd; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.nio.*; |
|
30 |
import java.io.*; |
|
31 |
import java.net.*; |
|
32 |
import java.rmi.*; |
|
33 |
import java.rmi.server.*; |
|
34 |
import sun.jvmstat.monitor.*; |
|
35 |
import sun.jvmstat.monitor.event.*; |
|
36 |
import sun.jvmstat.monitor.remote.*; |
|
37 |
||
38 |
/** |
|
39 |
* Concrete implementation of the RemoteHost interface for the HotSpot |
|
40 |
* PerfData <em>rmi:</em> protocol. |
|
41 |
* <p> |
|
42 |
* This class provides remote access to the instrumentation exported |
|
43 |
* by HotSpot Java Virtual Machines through the PerfData shared memory |
|
44 |
* interface. |
|
45 |
* |
|
46 |
* @author Brian Doherty |
|
47 |
* @since 1.5 |
|
48 |
*/ |
|
49 |
public class RemoteHostImpl implements RemoteHost, HostListener { |
|
50 |
||
51 |
private MonitoredHost monitoredHost; |
|
52 |
private Set<Integer> activeVms; |
|
53 |
||
54 |
public RemoteHostImpl() throws MonitorException { |
|
55 |
try { |
|
56 |
monitoredHost = MonitoredHost.getMonitoredHost("localhost"); |
|
57 |
} catch (URISyntaxException e) { } |
|
58 |
||
59 |
activeVms = monitoredHost.activeVms(); |
|
60 |
monitoredHost.addHostListener(this); |
|
61 |
} |
|
62 |
||
63 |
public RemoteVm attachVm(int lvmid, String mode) |
|
64 |
throws RemoteException, MonitorException { |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24969
diff
changeset
|
65 |
Integer v = lvmid; |
2 | 66 |
RemoteVm stub = null; |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
5506
diff
changeset
|
67 |
StringBuilder sb = new StringBuilder(); |
2 | 68 |
|
69 |
sb.append("local://").append(lvmid).append("@localhost"); |
|
70 |
if (mode != null) { |
|
27957
24b4e6082f19
8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents:
25859
diff
changeset
|
71 |
sb.append("?mode=").append(mode); |
2 | 72 |
} |
73 |
||
74 |
String vmidStr = sb.toString(); |
|
75 |
||
76 |
try { |
|
77 |
VmIdentifier vmid = new VmIdentifier(vmidStr); |
|
78 |
MonitoredVm mvm = monitoredHost.getMonitoredVm(vmid); |
|
79 |
RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm); |
|
80 |
stub = (RemoteVm) UnicastRemoteObject.exportObject(rvm, 0); |
|
81 |
} |
|
82 |
catch (URISyntaxException e) { |
|
83 |
throw new RuntimeException("Malformed VmIdentifier URI: " |
|
84 |
+ vmidStr, e); |
|
85 |
} |
|
86 |
return stub; |
|
87 |
} |
|
88 |
||
89 |
public void detachVm(RemoteVm rvm) throws RemoteException { |
|
90 |
rvm.detach(); |
|
91 |
} |
|
92 |
||
93 |
public int[] activeVms() throws MonitorException { |
|
94 |
Object[] vms = null; |
|
95 |
int[] vmids = null; |
|
96 |
||
97 |
vms = monitoredHost.activeVms().toArray(); |
|
98 |
vmids = new int[vms.length]; |
|
99 |
||
100 |
for (int i = 0; i < vmids.length; i++) { |
|
101 |
vmids[i] = ((Integer)vms[i]).intValue(); |
|
102 |
} |
|
103 |
return vmids; |
|
104 |
} |
|
105 |
||
106 |
public void vmStatusChanged(VmStatusChangeEvent ev) { |
|
107 |
synchronized(this.activeVms) { |
|
108 |
activeVms.retainAll(ev.getActive()); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
public void disconnected(HostEvent ev) { |
|
113 |
// we only monitor the local host, so this event shouldn't occur. |
|
114 |
} |
|
115 |
} |