1 23 24 29 package com.sun.enterprise.jmx.kstat; 30 31 import java.util.HashMap ; 32 import java.util.Set ; 33 34 import com.sun.cli.util.ClassUtil; 35 import com.sun.cli.util.stringifier.SmartStringifier; 36 37 public final class kstat 38 { 39 final String mModuleName; 40 final int mInstanceNumber; 41 final String mkstatName; 42 final HashMap mAttributes; 43 44 public static class kstatAttribute 45 { 46 public final String mName; 47 public final Object mValue; 48 49 50 private static Object 51 tryType( Class theClass, String input ) 52 { 53 Object value = null; 54 55 try 56 { 57 value = ClassUtil.InstantiateFromString( theClass, input ); 58 } 59 catch( Exception e ) 60 { 61 } 63 return( value ); 64 } 65 66 private static Object 67 createValue( String input ) 68 { 69 Object value = tryType( Long .class, input ); 70 if ( value == null ) 71 { 72 value = tryType( Double .class, input ); 73 } 74 if ( value == null ) 75 { 76 value = input; 77 } 78 79 return( value ); 80 } 81 82 public 83 kstatAttribute( String name, String value ) 84 { 85 mName = name; 86 mValue = createValue( value ); 87 } 88 public String 89 toString() 90 { 91 return( mName + "=" + mValue ); 92 } 93 }; 94 95 public 96 kstat( 97 String moduleName, 98 int instanceNumber, 99 String kstatName ) 100 { 101 mModuleName = moduleName; 102 mkstatName = kstatName; 103 mInstanceNumber = instanceNumber; 104 mAttributes = new HashMap (); 105 } 106 public void 107 addAttribute( kstatAttribute attr ) 108 { 109 mAttributes.put( attr.mName, attr ); 110 } 111 112 String 113 getModuleName() 114 { 115 return( mModuleName ); 116 } 117 118 int 119 getInstanceNumber() 120 { 121 return( mInstanceNumber ); 122 } 123 124 String 125 getName() 126 { 127 return( mkstatName ); 128 } 129 130 Class 131 getAttributeType( String name ) 132 { 133 final Object value = getValue( name ); 134 return( value.getClass() ); 135 } 136 137 String 138 getScopedName( char delim ) 139 { 140 return( getScopedName( mModuleName, mInstanceNumber, mkstatName, delim ) ); 141 } 142 143 String 144 getScopedName( ) 145 { 146 return( getScopedName( ':' ) ); 147 } 148 149 public static String 150 getScopedName( String moduleName, int instanceNumber, String name, char delim) 151 { 152 return( moduleName + delim + instanceNumber + delim + name ); 153 } 154 155 public static String 156 getScopedName( String moduleName, int instanceNumber, String name ) 157 { 158 return( getScopedName( moduleName, instanceNumber, name, ':' ) ); 159 } 160 161 Set 162 getAttributeNames() 163 { 164 return( mAttributes.keySet() ); 165 } 166 167 public Object 168 getValue( String attributeName ) 169 { 170 final kstatAttribute attr = (kstatAttribute)mAttributes.get( attributeName ); 171 172 Object value = null; 173 if ( attr != null ) 174 { 175 value = attr.mValue; 176 } 177 178 return( value ); 179 } 180 181 public String 182 toString() 183 { 184 return( getScopedName( ':' ) + "\n" + SmartStringifier.toString( mAttributes ) ); 185 } 186 }; 187 188 189 | Popular Tags |