01: /*
02: * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
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: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.management.counter.perf;
27:
28: import sun.management.counter.*;
29:
30: import java.nio.LongBuffer;
31: import java.nio.ReadOnlyBufferException;
32:
33: public class PerfLongArrayCounter extends AbstractCounter implements
34: LongArrayCounter {
35:
36: LongBuffer lb;
37:
38: PerfLongArrayCounter(String name, Units u, Variability v,
39: int flags, int vectorLength, LongBuffer lb) {
40:
41: super (name, u, v, flags, vectorLength);
42: this .lb = lb;
43: }
44:
45: public Object getValue() {
46: return longArrayValue();
47: }
48:
49: /**
50: * Get a copy of the elements of the LongArrayCounter.
51: */
52: public long[] longArrayValue() {
53:
54: lb.position(0);
55: long[] l = new long[lb.limit()];
56:
57: // copy the bytes
58: lb.get(l);
59:
60: return l;
61: }
62:
63: /**
64: * Get the value of an element of the LongArrayCounter object.
65: */
66: public long longAt(int index) {
67: lb.position(index);
68: return lb.get();
69: }
70:
71: /**
72: * Serialize as a snapshot object.
73: */
74: protected Object writeReplace()
75: throws java.io.ObjectStreamException {
76: return new LongArrayCounterSnapshot(getName(), getUnits(),
77: getVariability(), getFlags(), getVectorLength(),
78: longArrayValue());
79: }
80: }
|