1 23 24 29 30 31 package com.sun.enterprise.admin.mbeans; 32 33 import com.sun.enterprise.admin.dottedname.*; 34 35 import javax.management.*; 36 import java.lang.reflect.Array ; 37 38 39 42 public class DottedNameGetSetMBeanImpl 43 extends StandardMBean implements DottedNameGetSetMBean 44 { 45 final DottedNameGetSetForConfig mConfigImpl; 46 final DottedNameGetSetForMonitoring mMonitoringImpl; 47 final DottedNameServerInfoCache mServerInfo; 48 49 long mTimeOfLastCall; 50 51 61 public 62 DottedNameGetSetMBeanImpl( 63 final MBeanServerConnection conn, 64 final DottedNameRegistry registry, 65 final DottedNameRegistry monitoringRegistry ) 66 throws NotCompliantMBeanException, MalformedObjectNameException 67 { 68 69 70 super( DottedNameGetSet.class ); 71 72 mServerInfo = new DottedNameServerInfoCache( createServerInfo( conn ) ); 73 74 mConfigImpl = new DottedNameGetSetForConfig( conn, registry, mServerInfo ); 75 mMonitoringImpl = new DottedNameGetSetForMonitoring( conn, monitoringRegistry, mServerInfo ); 76 } 77 78 static private final long CLEAR_CACHE_INTERVAL_MILLIS = 10 * 60 * 1000; 80 81 protected void 82 pre() 83 { 84 mServerInfo.refresh(); 85 86 final long now = System.currentTimeMillis(); 87 if ( (now - mTimeOfLastCall) > CLEAR_CACHE_INTERVAL_MILLIS ) 88 { 89 DottedNameFactory.getInstance().clear(); 90 } 91 92 mTimeOfLastCall = now; 93 } 94 95 protected DottedNameServerInfo 97 createServerInfo( final MBeanServerConnection conn ) 98 { 99 return( new DottedNameServerInfoImpl( conn ) ); 100 } 101 102 protected boolean 103 checkGetResults( final Object [] results ) 104 { 105 boolean good = true; 106 107 for( int i = 0; i < results.length; ++i ) 108 { 109 final Object o = results[ i ]; 110 111 if ( ! (o instanceof Attribute || 112 o instanceof Attribute[] || 113 o instanceof Exception ) ) 114 { 115 good = false; 117 break; 118 } 119 } 120 return( good ); 121 } 122 123 protected boolean 124 checkSetResults( final Object [] results ) 125 { 126 boolean good = true; 127 128 for( int i = 0; i < results.length; ++i ) 129 { 130 final Object o = results[ i ]; 131 132 if ( ! (o instanceof Attribute || 133 o instanceof Exception ) ) 134 { 135 good = false; 136 break; 137 } 138 } 139 return( good ); 140 } 141 142 145 private boolean 146 hasIdenticalElementClasses( final Object [] a ) 147 { 148 boolean isUniform = true; 149 150 if ( a.length > 0 ) 151 { 152 final Class matchType = a[ 0 ].getClass(); 153 154 for( int i = 1; i < a.length; ++i ) 155 { 156 if ( a[ i ].getClass() != matchType ) 157 { 158 isUniform = false; 159 break; 160 } 161 } 162 } 163 164 return( isUniform ); 165 } 166 167 171 protected Object [] 172 convertArrayType( final Object [] input ) 173 { 174 Object [] result = input; 175 176 if ( hasIdenticalElementClasses( input ) && input.length != 0 ) 177 { 178 result = (Object [])Array.newInstance( input[ 0 ].getClass(), input.length ); 179 180 for( int i = 0; i < input.length; ++i ) 181 { 182 result[ i ] = input[ i ]; 183 } 184 } 185 186 return( result ); 187 } 188 189 protected Object [] 190 dottedNameAnyGet( DottedNameGetSetMBeanBase impl, final String [] names ) 191 { 192 pre(); 193 194 final Object [] results = impl.dottedNameGet( names ); 195 196 assert( checkGetResults( results ) ); 197 198 assert( results.length == names.length ); 199 return( convertArrayType( results ) ); 200 } 201 202 protected Object 203 dottedNameAnyGet( DottedNameGetSetMBeanBase impl, final String name ) 204 { 205 final Object [] results = dottedNameAnyGet( impl, new String [] { name } ); 206 207 return( results[ 0 ] ); 208 } 209 210 public Object [] 211 dottedNameGet( final String [] names ) 212 { 213 return( dottedNameAnyGet( mConfigImpl, names ) ); 214 } 215 216 public Object 217 dottedNameGet( final String name ) 218 { 219 final Object result = dottedNameAnyGet( mConfigImpl, name ); 220 return( result ); 221 } 222 223 public Object [] 224 dottedNameSet( final String [] nameValuePairs ) 225 { 226 pre(); 227 228 Object [] results = mConfigImpl.dottedNameSet( nameValuePairs ); 229 230 assert( checkSetResults( results ) ); 231 assert( results.length == nameValuePairs.length ); 232 233 return( convertArrayType( results ) ); 234 } 235 236 public Object 237 dottedNameSet( final String nameValuePair ) 238 { 239 final Object [] results = dottedNameSet( new String [] { nameValuePair } ); 240 241 return( results[ 0 ] ); 242 } 243 244 public String [] 245 dottedNameList( final String [] namePrefixes ) 246 { 247 pre(); 248 249 return( mConfigImpl.dottedNameList( namePrefixes ) ); 250 } 251 252 254 public Object [] 255 dottedNameMonitoringGet( final String [] names ) 256 { 257 return( dottedNameAnyGet( mMonitoringImpl, names ) ); 258 } 259 260 public Object 261 dottedNameMonitoringGet( final String name ) 262 { 263 return( dottedNameAnyGet( mMonitoringImpl, name ) ); 264 } 265 266 public String [] 267 dottedNameMonitoringList( final String [] namePrefixes ) 268 { 269 pre(); 270 271 return( mMonitoringImpl.dottedNameList( namePrefixes ) ); 272 } 273 } 274 275 276 279 final class DottedNameGetSetForMonitoring extends DottedNameGetSetMBeanBase 280 { 281 final DottedNameResolver mMonitoringResolver; 282 283 public 284 DottedNameGetSetForMonitoring( 285 final MBeanServerConnection conn, 286 final DottedNameRegistry registry, 287 final DottedNameServerInfo serverInfo ) 288 throws MalformedObjectNameException 289 { 290 super( conn, registry, serverInfo ); 291 292 mMonitoringResolver = new DottedNameResolverFromRegistry( registry ); 294 } 295 296 297 DottedNameResolver 298 getResolver( ) 299 { 300 return( mMonitoringResolver ); 301 } 302 303 304 DottedNameQuery 305 createQuery( ) 306 { 307 return( mRegistry ); 309 } 310 } 311 | Popular Tags |