Package test.remoting

Source Code of test.remoting.RemotingPerformanceTestCase$TestThread

/**
* @(#)$Id: RemotingPerformanceTestCase.java,v 1.5 2003/01/08 23:07:04 telrod Exp $
*
* This code is PROPRIETARY AND CONFIDENTIAL to Vocalocity, Inc.
* -- DO NOT RE-DISTRIBUTE THIS SOURCE CODE WITHOUT EXPRESS PERMISSION. --
*
* This source code is Copyright (c) 2002 by Vocalocity, Inc.
* All Rights Reserved.
*
* The source code for this program is not published or
* otherwise divested of its trade secrets, irrespective
* of what has been deposited with the US Copyright Office.
*
*/
package test.remoting;

import java.net.InetAddress;

import junit.framework.TestCase;
import org.jboss.mx.remote.connector.ConnectorFactory;
import org.jboss.mx.remote.connector.socket.SocketConnector;
import org.jboss.mx.remote.*;

import javax.management.MBeanServerFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
* RemotingPerformanceTestCase is a test case for remote performance

* @author <a href="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
* @version $Revision: 1.5 $
*/
public class RemotingPerformanceTestCase extends TestCase
{
    static final int COUNT = 10000;

    public RemotingPerformanceTestCase (String name)
    {
        super(name);
    }
    public void testPerformance () throws Exception
    {
        System.out.println("Testing JMX Remoting Performance ...");
        MBeanServer server=MBeanServerFactory.createMBeanServer();

        // create a local connector
        SocketConnector connector=new SocketConnector();
        server.registerMBean(connector,new ObjectName("jmx.remoting:type=Connector,transport=socket"));
        connector.start();

        // create a remote connector looped-back to ourself
        MBeanServerConnection conn=new MBeanServerConnection("socket",JMXUtil.getServerId(server),InstanceID.getID(server),InetAddress.getLocalHost(),connector.getTransportProperties());
        MBeanServer remoteserver=ConnectorFactory.createConnector(conn);

        TestThread local=new TestThread("Local MBeanServer executed "+COUNT+" iterations ...",server,COUNT);
        TestThread remote=new TestThread("Remote MBeanServer executed "+COUNT+" iterations ...",remoteserver,COUNT);
        local.start();
        remote.start();

        local.join(1000L);
        remote.join(120000L);

        ConnectorFactory.destroyConnector(JMXUtil.getServerId(remoteserver));
        server.unregisterMBean(new ObjectName("jmx.remoting:type=Connector,transport=socket"));
        connector.stop();
        connector.destroy();

        server=null;
        local = null;
        remote = null;
        connector = null;
    }

    public static void main(String[] args)
    {
        try
        {
            new RemotingPerformanceTestCase("RemotingPerformanceTestCase::main").testPerformance();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

    private final class TestThread extends Thread
    {
        final MBeanServer server;
        final int count;
        final String msg;

        TestThread (String name, MBeanServer remote, int iter)
        {
           msg=name;
           server=remote;
           count=iter;
        }
        public void run ()
        {
            long started = System.currentTimeMillis();
            try
            {
                for (int c=0;c<count;c++)
                {
                    server.getMBeanCount();
                }
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
            finally
            {
                long t = (System.currentTimeMillis()-started);
                System.out.println(msg+" "+t+" ms - "+Float.toString(t/count)+" ms/iter");
            }
        }
    }
}
TOP

Related Classes of test.remoting.RemotingPerformanceTestCase$TestThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.