1 23 24 29 30 package com.sun.cli.jmx.test; 31 32 33 import java.lang.reflect.Array ; 34 import java.util.Arrays ; 35 import java.util.ListIterator ; 36 37 import javax.management.MBeanServerConnection ; 38 import javax.management.remote.JMXServiceURL ; 39 import javax.management.remote.JMXConnector ; 40 import javax.management.remote.JMXConnectorFactory ; 41 42 import com.sun.cli.jmx.cmd.CmdReader; 43 import com.sun.cli.jmx.support.StringifierRegistryIniter; 44 import com.sun.cli.jmx.support.StandardAliasesIniter; 45 import com.sun.cli.jmx.cmd.ArgHelper; 46 import com.sun.cli.jmx.cmd.ArgHelperImpl; 47 import com.sun.cli.jmx.cmd.ArgHelperOptionsInfo; 48 49 import com.sun.cli.jmx.support.CLISupportMBeanProxy; 50 import com.sun.cli.jmx.support.AliasMgrMBean; 51 import com.sun.cli.jmx.support.AliasMgrHashMapImpl; 52 import com.sun.cli.jmx.support.AliasMgr; 53 import com.sun.cli.jmx.support.CLISupport; 54 import com.sun.cli.jmx.support.CLISupportMBean; 55 56 import com.sun.cli.jmx.cmd.ArgHelperImpl; 57 import com.sun.cli.jmx.cmd.ArgHelperOptionsInfo; 58 59 62 63 public class TestClientMain implements NotificationTester.ThroughputCallback 64 { 65 long mMilliseconds = 0; 66 long mNumCalls = 0; 67 long mStartTime = 0; 68 long mTotalNumCalls = 0; 69 short mNumThreads = 1; 70 short mNumAveraged = 0; 71 Object mCritical = new Object (); 72 73 74 TestClientMain( ) 75 { 76 } 77 78 long 79 now() 80 { 81 return( System.currentTimeMillis() ); 82 } 83 84 private static void 85 p( Object arg ) 86 { 87 System.out.println( arg.toString() ); 88 } 89 90 public void 91 throughputReport( long milliseconds, long numCalls ) 92 { 93 String progString = ""; 94 95 synchronized ( mCritical ) 96 { 97 mTotalNumCalls += numCalls; 98 99 ++mNumAveraged; 100 if ( mNumAveraged > mNumThreads * 8 ) 101 { 102 mMilliseconds = 0; 104 mNumCalls = 0; 105 mNumAveraged = 0; 106 } 107 108 mMilliseconds += milliseconds; 109 mNumCalls += numCalls; 110 111 final double rollingCallsPerSec = mNumCalls / ((mMilliseconds / 1000.0) / (double)mNumThreads); 112 final double totalCallsPerSec = mTotalNumCalls / ((now() - mStartTime) / 1000.0); 113 114 progString = mNumThreads + " threads: " + 115 (long)rollingCallsPerSec + " (rolling) " + 116 (long)totalCallsPerSec + " (total)"; 117 } 118 119 p( progString ); 121 } 122 123 private void 124 testNotifications( String host, int port ) throws Exception  125 { 126 System.out.println( "Testing: " + host + ":" + port + ", threads = " + mNumThreads ); 127 128 final int kNumInvokes = 1 * 1024; 129 130 mStartTime = System.currentTimeMillis(); 131 for( int i = 0; i < mNumThreads; ++i ) 132 { 133 NotificationTester test = new NotificationTester( host, port); 134 135 test.RunNotifTest( 0 ); 137 } 138 } 139 140 141 private static JMXConnector  142 establishConnection( String host, int port ) 143 throws Exception  144 { 145 final JMXServiceURL url = new JMXServiceURL ( "service:jmx:jmxmp://" + host + ":" + port ); 146 147 JMXConnector conn = JMXConnectorFactory.connect( url ); 148 149 return( conn ); 150 } 151 152 private CLISupportMBeanProxy 153 createProxy(MBeanServerConnection managedServer, boolean runLocally ) throws Exception  154 { 155 CLISupportMBeanProxy proxy = null; 156 157 AliasMgrMBean aliasMgr = null; 158 CLISupportMBean cliSupport = null; 159 160 if ( runLocally ) 161 { 162 final AliasMgrHashMapImpl aliasMgrImpl = new AliasMgrHashMapImpl(); 163 aliasMgrImpl.load( AliasMgrHashMapImpl.DEFAULT_FILENAME ); 164 aliasMgr = new AliasMgr( aliasMgrImpl ); 165 StandardAliasesIniter.init( aliasMgr ); 166 167 cliSupport = new CLISupport( managedServer, aliasMgr ); 168 169 } 170 else 171 { 172 aliasMgr = CLISupportMBeanProxy.createAliasMgrProxy( managedServer ); 173 cliSupport = CLISupportMBeanProxy.createCLISupportProxy( managedServer ); 174 } 175 176 proxy = new CLISupportMBeanProxy( aliasMgr, cliSupport); 177 178 return( proxy ); 179 } 180 181 private void 182 testCLISupport( MBeanServerConnection conn, boolean runLocally) throws Exception  183 { 184 final CLISupportMBeanProxy proxy = createProxy( conn, runLocally ); 185 186 final CLISupportTester tester = new CLISupportTester( conn, proxy ); 187 tester.Run(); 188 } 189 190 191 private final static String OPTIONS = "host=1 port=2 interactive localsupport"; 192 193 public static void 194 main(String args[]) 195 { 196 try 197 { 198 final ArgHelperOptionsInfo optionInfo = new ArgHelperOptionsInfo( OPTIONS ); 199 200 final ListIterator iter = Arrays.asList( args ).listIterator(); 201 final ArgHelper argHelper = new ArgHelperImpl( iter, optionInfo); 202 203 final Integer port = argHelper.getInteger( "--port" ); 204 final String host = argHelper.getString( "--host", "localhost"); 205 final boolean interactive = argHelper.getBoolean( "--interactive", Boolean.FALSE).booleanValue(); 206 final boolean runLocally = argHelper.getBoolean( "--localsupport", Boolean.FALSE ).booleanValue(); 207 208 if ( port == null ) 209 { 210 System.out.println( "USAGE: TestClient --port=<port-number>" ); 211 System.exit( 1 ); 212 } 213 214 final TestClientMain testMain = new TestClientMain( ); 215 216 new StringifierRegistryIniter(); 217 218 final JMXConnector jmxConnector = establishConnection( host, port.intValue() ); 219 final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection(); 220 221 p( "Connected to: " + host + ":" + port ); 222 223 p( ( runLocally ? "Running with local CLI support.":"Running with remote CLI support") ); 224 225 testMain.testCLISupport( conn, runLocally ); 227 } 228 catch( Exception e ) 229 { 230 p( e ); 231 } 232 } 233 }; 234 235 236 | Popular Tags |