FileDocCategorySizeDatePackage
NotificationTester.javaAPI DocGlassfish v2 API7568Fri May 04 22:24:54 BST 2007com.sun.cli.jmx.test

NotificationTester

public class NotificationTester extends Thread implements NotificationListener

Fields Summary
MBeanServerConnection
mServer
JMXConnector
mConnection
String
mHost
int
mPort
ThroughputCallback
mThroughputCallback
long
mNotifCount
String
mName
int
mOuterLoop
int
mNumIterations
Constructors Summary
public NotificationTester(String host, int port)

		mHost	= host;
		mPort	= port;
		
		mConnection	= Connect( host, port );
		mServer		= mConnection.getMBeanServerConnection( );
	
Methods Summary
private javax.management.remote.JMXConnectorConnect(java.lang.String host, int port)

		final JMXServiceURL	url	= new JMXServiceURL( "service:jmx:jmxmp://" + host + ":" + port );
			
		JMXConnector conn	= JMXConnectorFactory.connect( url );
		return( conn );
	
public voidRunMultiplePerConnection(int outerCount, int numIterations)

		final ObjectName	name	= new ObjectName( "foo" );
		//final ObjectName	name	= new ObjectName( TestShared.kSimpleDynamicName );
			
		for( int outer = 0; outer < outerCount; ++outer )
		{
			final long	startTime	= System.currentTimeMillis();
			
			for( int i = 0; i < numIterations; ++i )
			{
				Object result	= mServer.getAttribute( name, "NotifsEmitted" );
			}
			
			final long	endTime	= System.currentTimeMillis();
			final long	elapsed	= endTime - startTime;
			
			//p( mName + ": " + numIterations / (elapsed / 1000.0) + " iterations/sec" );
			mThroughputCallback.throughputReport( elapsed, numIterations );
		}
	
public voidRunMultiplePerConnectionThreaded(java.lang.String name, int outerLoop, int numIterations, com.sun.cli.jmx.test.NotificationTester$ThroughputCallback throughputCallback)

		mName				= name;
		mOuterLoop			= outerLoop;
		mNumIterations		= numIterations;
		mThroughputCallback	= throughputCallback;
		
		this.start();
	
public voidRunNotifTest(long sleepMillis)

             final ObjectName emitterName = new ObjectName(CLISupportStrings.CLI_SIMPLE_TESTEE_TARGET);

             mNotifCount = 0;
             boolean success = false;

             try {
                 p("adding listener");
                 mServer.addNotificationListener(emitterName, this, null, null);
                 p("setting attribute");
                 mServer.setAttribute(emitterName,
                                      new Attribute("NotifMillis",
                                                    Long.valueOf(sleepMillis)));
                 p("starting");
                 mServer.invoke(emitterName, "startNotif", null, null);
                 success = true;
                 p("started");
             }
             catch (Exception e) {
                 p("caught exception: " + e);
             }
             long startTime = System.currentTimeMillis();

             while (true) {
                 Thread.sleep(500);
                 final long notifCount = mNotifCount;
                 final long elapsedMillis = System.currentTimeMillis() -
                                            startTime;
                 final double rate = (double) notifCount /
                                     (elapsedMillis / 1000.0);

                 System.out.println("total notifications: " + notifCount + " = " +
                                    (rate * 10.0) / 10.0 + "/sec");
             }
         
public voidRunSinglePerConnection(int numConnections)

		final long	startTime	= System.currentTimeMillis();
		
		final ObjectName	name	= new ObjectName( CLISupportStrings.CLI_SUPPORT_TARGET );
		for( int i = 0; i < numConnections; ++i )
		{
			JMXConnector			conn	= Connect( mHost, mPort );
			MBeanServerConnection	server	= conn.getMBeanServerConnection( );
			
			Object result	= server.getAttribute( name, "NbChanges" );
			conn.close();
		}
		
		final long	endTime	= System.currentTimeMillis();
		final long	elapsed	= endTime - startTime;
		
		p( "elapsed = " + elapsed );
		p( "connections per second = " + numConnections / (elapsed / 1000.0) );
	
public voidhandleNotification(javax.management.Notification notification, java.lang.Object handback)

	
		 
       
    
    	++mNotifCount;
    
private static voidp(java.lang.Object arg)

		System.out.println( arg.toString() );
	
public voidrun()

		try
		{
			RunMultiplePerConnection( mOuterLoop, mNumIterations );
		}
		catch( Exception e )
		{
			p( e );
		}