KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > test > CLISupportSimpleTestee


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin-cli/cli-api/src/java/com/sun/cli/jmx/test/CLISupportSimpleTestee.java,v 1.3 2005/12/25 03:45:51 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:51 $
28  */

29  
30 package com.sun.cli.jmx.test;
31
32
33 import java.io.Serializable JavaDoc;
34 import java.net.URL JavaDoc;
35 import java.net.URI JavaDoc;
36
37 import java.util.Properties JavaDoc;
38
39 import javax.management.AttributeChangeNotification JavaDoc;
40 import javax.management.NotificationBroadcasterSupport JavaDoc;
41 import javax.management.Notification JavaDoc;
42
43
44 public class CLISupportSimpleTestee
45     extends NotificationBroadcasterSupport JavaDoc
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 JavaDoc a1, Boolean JavaDoc a2, Character JavaDoc a3, Byte JavaDoc a4, Short JavaDoc a5,
61                 Integer JavaDoc a6, Long JavaDoc a7, Float JavaDoc a8, Double JavaDoc a9,
62                 java.math.BigInteger JavaDoc a10, java.math.BigDecimal JavaDoc a11)
63     {
64         // no need to do anything
65
}
66     
67         public void
68     test11MixedArgs( String JavaDoc a1, boolean a2, char a3, byte a4, short a5,
69                         int a6, long a7, float a8, double a9,
70                         java.math.BigInteger JavaDoc a10, java.math.BigDecimal JavaDoc a11)
71     {
72         // no need to do anything
73
}
74     
75         public String JavaDoc
76     testString( String JavaDoc s )
77     {
78         return( s );
79     }
80     
81         public Object JavaDoc
82     testObject( Object JavaDoc obj )
83     {
84         return( obj );
85     }
86
87         public Integer JavaDoc
88     testInteger( Integer JavaDoc i )
89     {
90         return( i );
91     }
92     
93         public int
94     test_int( int i )
95     {
96         return( i );
97     }
98     
99         public Object JavaDoc []
100     testObjectArray( Object JavaDoc [] objects )
101     {
102         return( objects );
103     }
104     
105     
106         public String JavaDoc
107     testcasesensitivity1()
108     {
109         return( "testcasesensitivity1" );
110     }
111         public String JavaDoc
112     testCASESENSITIVITY1()
113     {
114         return( "testCASESENSITIVITY1" );
115     }
116         public String JavaDoc
117     testCaseSensitivity1()
118     {
119         return( "testCaseSensitivity1" );
120     }
121     
122         public String JavaDoc
123     testCaseSensitivity2()
124     {
125         return( "testCaseSensitivity2" );
126     }
127     
128     
129         public URL JavaDoc
130     testURL( URL JavaDoc u )
131     {
132         return( u );
133     }
134
135         public URI JavaDoc
136     testURI( URI JavaDoc u )
137     {
138         return( u );
139     }
140     
141     
142     private static class AintGonnaHaveIt implements Serializable JavaDoc
143     {
144             public
145         AintGonnaHaveIt()
146         {
147         }
148     };
149     
150         public Object JavaDoc
151     testUnknownType()
152     {
153         return( new AintGonnaHaveIt() );
154     }
155         public Object JavaDoc
156     getUnknownType()
157     {
158         return( new AintGonnaHaveIt() );
159     }
160     
161     
162 //------------------------------------------------------------------------
163

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             // restart with new interval
176
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 JavaDoc 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 JavaDoc notif = new AttributeChangeNotification JavaDoc( this,
227             mNumNotifsEmitted, // use this as sequence number
228
System.currentTimeMillis(),
229             "did it again",
230             "NotifsEmitted",
231             "java.lang.long",
232             new Long JavaDoc( mNumNotifsEmitted ),
233             new Long JavaDoc( 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 JavaDoc
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 JavaDoc e )
274                 {
275                 }
276             }
277             
278             keepGoing = mHost.emitNotif( this );
279         }
280     }
281 };
282
283
284
285
Popular Tags