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.jvmstat.perfdata.monitor.protocol.rmi;
|
|
27 |
|
|
28 |
import sun.jvmstat.monitor.*;
|
|
29 |
import sun.jvmstat.monitor.remote.*;
|
|
30 |
import sun.jvmstat.perfdata.monitor.*;
|
|
31 |
import java.io.*;
|
|
32 |
import java.rmi.RemoteException;
|
|
33 |
import java.nio.ByteBuffer;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* The concrete PerfDataBuffer implementation for the <em>rmi:</em>
|
|
37 |
* protocol for the HotSpot PerfData monitoring implementation.
|
|
38 |
* <p>
|
|
39 |
* This class is responsible for acquiring the instrumentation buffer
|
|
40 |
* data for a remote target HotSpot Java Virtual Machine.
|
|
41 |
*
|
|
42 |
* @author Brian Doherty
|
|
43 |
* @since 1.5
|
|
44 |
*/
|
|
45 |
public class PerfDataBuffer extends AbstractPerfDataBuffer {
|
|
46 |
|
|
47 |
private RemoteVm rvm;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Create a PerfDataBuffer instance for accessing the specified
|
|
51 |
* instrumentation buffer.
|
|
52 |
*
|
|
53 |
* @param rvm the proxy to the remote MonitredVm object
|
|
54 |
* @param lvmid the local Java Virtual Machine Identifier of the
|
|
55 |
* remote target.
|
|
56 |
*
|
|
57 |
* @throws MonitorException
|
|
58 |
*/
|
|
59 |
public PerfDataBuffer(RemoteVm rvm, int lvmid) throws MonitorException {
|
|
60 |
|
|
61 |
this.rvm = rvm;
|
|
62 |
try {
|
|
63 |
ByteBuffer buffer = ByteBuffer.allocate(rvm.getCapacity());
|
|
64 |
sample(buffer);
|
|
65 |
createPerfDataBuffer(buffer, lvmid);
|
|
66 |
|
|
67 |
} catch (RemoteException e) {
|
|
68 |
throw new MonitorException("Could not read data for remote JVM "
|
|
69 |
+ lvmid, e);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Get a copy of the remote instrumentation buffer.
|
|
75 |
*<p>
|
|
76 |
* The data in the remote instrumentation buffer is copied into
|
|
77 |
* the local byte buffer.
|
|
78 |
*
|
|
79 |
* @param buffer the buffer to receive the copy of the remote
|
|
80 |
* instrumentation buffer.
|
|
81 |
* @throws RemoteException Thrown on any communications errors with
|
|
82 |
* the remote system.
|
|
83 |
*/
|
|
84 |
public void sample(ByteBuffer buffer) throws RemoteException {
|
|
85 |
assert buffer != null;
|
|
86 |
assert rvm != null;
|
|
87 |
synchronized(buffer) {
|
|
88 |
buffer.clear();
|
|
89 |
buffer.put(rvm.getBytes());
|
|
90 |
}
|
|
91 |
}
|
|
92 |
}
|