1 23 24 29 30 package com.sun.cli.jmx.test; 31 32 33 import java.io.Serializable ; 34 import java.net.URL ; 35 import java.net.URI ; 36 37 import java.util.Properties ; 38 39 import javax.management.AttributeChangeNotification ; 40 import javax.management.NotificationBroadcasterSupport ; 41 import javax.management.Notification ; 42 43 44 public class CLISupportSimpleTestee 45 extends NotificationBroadcasterSupport 46 implements CLISupportSimpleTesteeMBean 47 48 { 49 volatile long mNotifMillis = 1000; 50 volatile long mNumNotifsEmitted; 51 EmitterThread mEmitterThread; 52 53 public 54 CLISupportSimpleTestee() 55 { 56 } 57 58 59 public void 60 test11ObjectArgs( String a1, Boolean a2, Character a3, Byte a4, Short a5, 61 Integer a6, Long a7, Float a8, Double a9, 62 java.math.BigInteger a10, java.math.BigDecimal a11) 63 { 64 } 66 67 public void 68 test11MixedArgs( String a1, boolean a2, char a3, byte a4, short a5, 69 int a6, long a7, float a8, double a9, 70 java.math.BigInteger a10, java.math.BigDecimal a11) 71 { 72 } 74 75 public String 76 testString( String s ) 77 { 78 return( s ); 79 } 80 81 public Object 82 testObject( Object obj ) 83 { 84 return( obj ); 85 } 86 87 public Integer 88 testInteger( Integer i ) 89 { 90 return( i ); 91 } 92 93 public int 94 test_int( int i ) 95 { 96 return( i ); 97 } 98 99 public Object [] 100 testObjectArray( Object [] objects ) 101 { 102 return( objects ); 103 } 104 105 106 public String 107 testcasesensitivity1() 108 { 109 return( "testcasesensitivity1" ); 110 } 111 public String 112 testCASESENSITIVITY1() 113 { 114 return( "testCASESENSITIVITY1" ); 115 } 116 public String 117 testCaseSensitivity1() 118 { 119 return( "testCaseSensitivity1" ); 120 } 121 122 public String 123 testCaseSensitivity2() 124 { 125 return( "testCaseSensitivity2" ); 126 } 127 128 129 public URL 130 testURL( URL u ) 131 { 132 return( u ); 133 } 134 135 public URI 136 testURI( URI u ) 137 { 138 return( u ); 139 } 140 141 142 private static class AintGonnaHaveIt implements Serializable 143 { 144 public 145 AintGonnaHaveIt() 146 { 147 } 148 }; 149 150 public Object 151 testUnknownType() 152 { 153 return( new AintGonnaHaveIt() ); 154 } 155 public Object 156 getUnknownType() 157 { 158 return( new AintGonnaHaveIt() ); 159 } 160 161 162 164 public long getNotifMillis() 165 { 166 return mNotifMillis; 167 } 168 169 public void setNotifMillis(long millis) 170 { 171 mNotifMillis = millis; 172 173 if ( mEmitterThread != null ) 174 { 175 stopNotif(); 177 startNotif(); 178 } 179 } 180 181 public long getNotifsEmitted() 182 { 183 return( mNumNotifsEmitted ); 184 } 185 186 187 public void resetNotifsEmitted() 188 { 189 mNumNotifsEmitted = 0; 190 } 191 192 193 synchronized public void startNotif() 194 { 195 stopNotif(); 196 197 System.out.println( "emitting notifications once per this many ms: " + mNotifMillis ); 198 mEmitterThread = new EmitterThread( this, mNotifMillis); 199 mEmitterThread.start(); 200 } 201 202 public void stopNotif() 203 { 204 if ( mEmitterThread != null ) 205 { 206 EmitterThread thread = mEmitterThread; 207 208 mEmitterThread = null; 209 try 210 { 211 thread.join( ); 212 } 213 catch( InterruptedException e ) 214 { 215 } 216 } 217 } 218 219 boolean emitNotif( EmitterThread thread ) 220 { 221 if ( mEmitterThread == null ) 222 { 223 return( false ); 224 } 225 226 final AttributeChangeNotification notif = new AttributeChangeNotification ( this, 227 mNumNotifsEmitted, System.currentTimeMillis(), 229 "did it again", 230 "NotifsEmitted", 231 "java.lang.long", 232 new Long ( mNumNotifsEmitted ), 233 new Long ( mNumNotifsEmitted + 1)); 234 235 ++mNumNotifsEmitted; 236 237 sendNotification( notif ); 238 239 System.out.println( "emitted another one" ); 240 return( true ); 241 } 242 } 243 244 245 class EmitterThread extends Thread 246 { 247 CLISupportSimpleTestee mHost; 248 final long mSleepMillis; 249 250 EmitterThread( CLISupportSimpleTestee host, long sleepMillis ) 251 { 252 super( "Emitter Thread" ); 253 mHost = host; 254 mSleepMillis = sleepMillis; 255 } 256 257 258 public void 259 run() 260 { 261 boolean keepGoing = true; 262 263 final long sleepMillis = mSleepMillis; 264 265 while ( keepGoing ) 266 { 267 if ( sleepMillis != 0 ) 268 { 269 try 270 { 271 Thread.sleep( sleepMillis ); 272 } 273 catch( InterruptedException e ) 274 { 275 } 276 } 277 278 keepGoing = mHost.emitNotif( this ); 279 } 280 } 281 }; 282 283 284 285 | Popular Tags |