KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > base > NotificationPerformanceTest


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 package com.sun.enterprise.management.base;
24
25 import java.io.IOException JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.Notification JavaDoc;
29 import javax.management.NotificationListener JavaDoc;
30 import javax.management.AttributeChangeNotification JavaDoc;
31 import javax.management.JMException JavaDoc;
32 import javax.management.MBeanServerConnection JavaDoc;
33
34 import com.sun.appserv.management.base.Util;
35
36 import com.sun.enterprise.management.support.TestDummy;
37 import com.sun.enterprise.management.support.TestDummyMBean;
38
39 import com.sun.enterprise.management.util.jmx.JMXTestBase;
40
41
42 /**
43  */

44 public final class NotificationPerformanceTest extends JMXTestBase
45 {
46     // built-into server already
47
private static final String JavaDoc IMPL_CLASSNAME = TestDummy.class.getName();
48     
49         public
50     NotificationPerformanceTest( )
51     {
52     }
53     
54         private ObjectName JavaDoc
55     createTestDummy( final String JavaDoc name )
56         throws JMException JavaDoc, IOException JavaDoc
57     {
58         ObjectName JavaDoc objectName =
59             Util.newObjectName( "NotificationPerformanceTest:name=" + name );
60         
61         final MBeanServerConnection JavaDoc conn = getMBeanServerConnection();
62         
63         if ( ! conn.isRegistered( objectName ) )
64         {
65             objectName =
66                 conn.createMBean( IMPL_CLASSNAME, objectName ).getObjectName();
67         }
68         
69         return objectName;
70     }
71     
72         public void
73     testNotificationPerformance()
74         throws JMException JavaDoc, IOException JavaDoc
75     {
76         final ObjectName JavaDoc objectName = createTestDummy( "testNotificationPerformance" );
77         
78         final TestDummyMBean test = newProxy( objectName, TestDummyMBean.class );
79         
80         final int ITER = 10;
81         final int COUNT = 1024 * 1024;
82         
83         for( int iter = 0; iter < ITER; ++iter )
84         {
85             final long elapsed =
86                 test.emitNotifications( "NotificationPerformanceTest.test", COUNT );
87             
88             final float rate = (elapsed == 0) ? (float)0.0 : (1000 * ((float)COUNT / (float)elapsed));
89             final String JavaDoc rateString = (elapsed == 0) ? "N/A" : "" + (int)rate;
90             
91             System.out.println( "Millis to emit " + COUNT + " Notifications: " + elapsed +
92                 " = " + rateString + " notifications/sec" );
93         }
94     }
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Popular Tags