1 26 27 28 package org.objectweb.benchmark.benchIce.latency; 29 30 import org.objectweb.benchmark.util.ResultPrinter; 32 33 40 public class Client 41 { 42 43 49 50 private int nb_step; 51 52 53 private int nb_step_invocation; 54 55 56 private int step_start; 57 58 59 private String result_file; 60 61 62 private String host; 63 64 65 private PingItfPrx ping = null; 66 67 68 Ice.Communicator ic = null; 69 70 76 81 82 public Client(String name) 83 { 84 result_file = name; 85 java.util.Properties properties = new java.util.Properties (); 86 87 try { 88 java.io.InputStream propStream = null; 89 90 propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties"); 92 properties.load(propStream); 93 94 nb_step = Integer.parseInt( properties.getProperty("step.number") ); 95 nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") ); 96 step_start = Integer.parseInt( properties.getProperty("step.start") ); 97 host = properties.getProperty("com.host"); 98 99 } catch (Exception e) { 100 e.printStackTrace(); 101 } 102 } 103 104 110 115 public static void main(String [] args) 116 { 117 if (args.length != 1) 118 { 119 System.out.println("Usage: Client <dest_file>"); 120 System.exit(0); 121 } 122 123 Client c = new Client(args[0]); 124 c.run(); 125 } 126 127 130 public void run() 131 { 132 try{ 133 ic = Ice.Util.initialize(new String [0]); 134 135 if( host.equals("localhost") ) 137 host = java.net.InetAddress.getLocalHost().getHostAddress().toString(); 138 139 Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -h "+host+" -p 10000"); 140 ping = PingItfPrxHelper.checkedCast(base); 141 }catch(Exception ex){ 142 ex.printStackTrace(); 143 } 144 145 test(); 147 } 148 149 152 public void test() 153 { 154 for (int i=0; i<step_start; i++) 156 ping.ping(); 157 158 System.out.println( "Running ICE Benchmark with " + nb_step + " step(s) of " 160 + nb_step_invocation +" method calls." ); 161 try{ 162 for(int j=0; j<nb_step; j++) 163 { 164 long timer = System.currentTimeMillis(); 165 166 for (int i=0; i<nb_step_invocation; i++) 167 ping.ping(); 168 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation ); 169 170 ResultPrinter p = new ResultPrinter(result_file); 172 p.write(timer); 173 p.close(); 174 } 175 }catch(Exception ex){ 176 ex.printStackTrace(); 177 } 178 179 ping.shutdown(); 181 ic.destroy(); 182 } 183 } 184 185 186 187 188 189 | Popular Tags |