1 26 27 package org.objectweb.benchmark.corba.latency; 28 29 import java.io.InputStreamReader ; 31 import java.io.BufferedReader ; 32 import java.net.Socket ; 33 34 import org.objectweb.benchmark.util.ResultPrinter; 35 import org.omg.CORBA.ORB ; 36 37 44 public class Client 45 { 46 52 53 private int nb_step; 54 55 56 private int nb_step_invocation; 57 58 59 private int step_start; 60 61 62 private String result_file; 63 64 65 private int ior_port; 66 67 68 private String host; 69 70 71 private ORB orb = null; 72 73 74 private PingItf ping_impl = null; 75 76 82 88 public Client(String name) 89 { 90 result_file = name; 91 java.util.Properties properties = new java.util.Properties (); 92 93 try { 94 java.io.InputStream propStream = null; 95 96 propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties"); 98 properties.load(propStream); 99 100 nb_step = Integer.parseInt( properties.getProperty("step.number") ); 101 nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") ); 102 step_start = Integer.parseInt( properties.getProperty("step.start") ); 103 host = properties.getProperty("com.host"); 104 105 propStream = getClass().getClassLoader().getResourceAsStream("build.properties"); 107 properties.load(propStream); 108 109 ior_port=Integer.parseInt( properties.getProperty("ior.port") ); 110 } catch (Exception e) { 111 e.printStackTrace(); 112 } 113 } 114 115 121 124 private void init_orb() 125 { 126 try { 127 java.io.InputStream propStream = null; 128 129 propStream = getClass().getClassLoader().getResourceAsStream("ORB.properties"); 130 System.getProperties().load(propStream); 131 }catch (Exception e) { 132 e.printStackTrace(); 133 } 134 } 135 136 142 147 public static void main(String [] args) 148 { 149 if (args.length != 1) 150 { 151 System.out.println("Usage: Client <dest_file>"); 152 System.exit(0); 153 } 154 155 Client c = new Client(args[0]); 156 c.run(); 157 } 158 159 162 public void run() 163 { 164 init_orb(); 166 orb = ORB.init(new String [0], null); 167 168 try{ 170 Socket s = new Socket (host,ior_port); 172 173 BufferedReader in =new BufferedReader (new InputStreamReader (s.getInputStream())); 174 org.omg.CORBA.Object obj = orb.string_to_object(in.readLine()); 175 176 ping_impl = PingItfHelper.narrow(obj); 177 }catch(Exception ex){ 178 ex.printStackTrace(); 179 } 180 181 test(); 183 184 orb.shutdown(false); 186 } 187 188 191 public void test() 192 { 193 for (int i=0; i<step_start; i++) 195 ping_impl.ping(); 196 197 System.out.println( "Running CORBA Benchmark with " + nb_step + " step(s) of " 199 + nb_step_invocation +" method calls." ); 200 try{ 201 for(int j=0; j<nb_step; j++) 202 { 203 long timer = System.currentTimeMillis(); 204 205 for (int i=0; i<nb_step_invocation; i++) 206 ping_impl.ping(); 207 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation ); 208 209 ResultPrinter p = new ResultPrinter(result_file); 211 p.write(timer); 212 p.close(); 213 } 214 }catch(Exception ex){ 215 ex.printStackTrace(); 216 } 217 218 ping_impl.shutdown(); 220 } 221 } 222 | Popular Tags |