1/* 2 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 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. 24 */ 25 26package sun.jvmstat.monitor; 27 28/** 29 * The base class for Instrumentation Monitoring Objects. This base class 30 * provides implementations of the {@link Monitor} methods that are common 31 * to all classes implementing the Monitor interface.. 32 * 33 * @author Brian Doherty 34 * @since 1.5 35 */ 36public abstract class AbstractMonitor implements Monitor { 37 protected String name; 38 protected Units units; 39 protected Variability variability; 40 protected int vectorLength; 41 protected boolean supported; 42 43 /** 44 * Create a vector instrumentation monitoring object with the given 45 * name and attributes. 46 * 47 * @param name the name to assign to this instrumentation object. 48 * @param units the units of measure attribute 49 * @param variability the variability attribute 50 * @param supported support level indicator 51 * @param vectorLength the length of the vector, or 0 if not a vector type. 52 */ 53 protected AbstractMonitor(String name, Units units, Variability variability, 54 boolean supported, int vectorLength) { 55 this.name = name; 56 this.units = units; 57 this.variability = variability; 58 this.vectorLength = vectorLength; 59 this.supported = supported; 60 } 61 62 /** 63 * Create a scalar instrumentation monitoring object with the given 64 * name and attributes. 65 * 66 * @param name the name to assign to this instrumentation object. 67 * @param units the units of measure attribute 68 * @param variability the variability attribute 69 * @param supported support level indicator 70 */ 71 protected AbstractMonitor(String name, Units units, Variability variability, 72 boolean supported) { 73 this(name, units, variability, supported, 0); 74 } 75 76 /** 77 * {@inheritDoc} 78 */ 79 public String getName() { 80 return name; 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 public String getBaseName() { 87 int baseIndex = name.lastIndexOf('.') + 1; 88 return name.substring(baseIndex); 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 public Units getUnits() { 95 return units; 96 } 97 98 /** 99 * {@inheritDoc} 100 */ 101 public Variability getVariability() { 102 return variability; 103 } 104 105 /** 106 * {@inheritDoc} 107 */ 108 public boolean isVector() { 109 return vectorLength > 0; 110 } 111 112 /** 113 * {@inheritDoc} 114 */ 115 public int getVectorLength() { 116 return vectorLength; 117 } 118 119 /** 120 * {@inheritDoc} 121 */ 122 public boolean isSupported() { 123 return supported; 124 } 125 126 /** 127 * {@inheritDoc} 128 */ 129 public abstract Object getValue(); 130} 131