1 23 package com.sun.enterprise.management.base; 24 25 import java.io.IOException ; 26 27 import javax.management.ObjectName ; 28 import javax.management.Notification ; 29 import javax.management.NotificationListener ; 30 import javax.management.AttributeChangeNotification ; 31 import javax.management.JMException ; 32 import javax.management.MBeanServerConnection ; 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 44 public final class NotificationPerformanceTest extends JMXTestBase 45 { 46 private static final String IMPL_CLASSNAME = TestDummy.class.getName(); 48 49 public 50 NotificationPerformanceTest( ) 51 { 52 } 53 54 private ObjectName 55 createTestDummy( final String name ) 56 throws JMException , IOException 57 { 58 ObjectName objectName = 59 Util.newObjectName( "NotificationPerformanceTest:name=" + name ); 60 61 final MBeanServerConnection 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 , IOException 75 { 76 final ObjectName 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 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 |