001: /*
002: * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.management.counter;
027:
028: import java.io.IOException;
029: import java.io.ObjectOutputStream;
030: import java.io.ObjectInputStream;
031:
032: /**
033: */
034: public abstract class AbstractCounter implements Counter {
035:
036: String name;
037: Units units;
038: Variability variability;
039: int flags;
040: int vectorLength;
041:
042: // Flags defined in hotspot implementation
043: class Flags {
044: static final int SUPPORTED = 0x1;
045: }
046:
047: protected AbstractCounter(String name, Units units,
048: Variability variability, int flags, int vectorLength) {
049: this .name = name;
050: this .units = units;
051: this .variability = variability;
052: this .flags = flags;
053: this .vectorLength = vectorLength;
054: }
055:
056: protected AbstractCounter(String name, Units units,
057: Variability variability, int flags) {
058: this (name, units, variability, flags, 0);
059: }
060:
061: /**
062: * Returns the name of the Performance Counter
063: */
064: public String getName() {
065: return name;
066: }
067:
068: /**
069: * Returns the Units for this Performance Counter
070: */
071: public Units getUnits() {
072: return units;
073: }
074:
075: /**
076: * Returns the Variability for this performance Object
077: */
078: public Variability getVariability() {
079: return variability;
080: }
081:
082: /**
083: * Return true if this performance counter is a vector
084: */
085: public boolean isVector() {
086: return vectorLength > 0;
087: }
088:
089: /**
090: * return the length of the vector
091: */
092: public int getVectorLength() {
093: return vectorLength;
094: }
095:
096: public boolean isInternal() {
097: return (flags & Flags.SUPPORTED) == 0;
098: }
099:
100: /**
101: * return the flags associated with the counter.
102: */
103: public int getFlags() {
104: return flags;
105: }
106:
107: public abstract Object getValue();
108:
109: public String toString() {
110: String result = getName() + ": " + getValue() + " "
111: + getUnits();
112: if (isInternal()) {
113: return result + " [INTERNAL]";
114: } else {
115: return result;
116: }
117: }
118:
119: private static final long serialVersionUID = 6992337162326171013L;
120:
121: }
|