1 26 27 package org.objectweb.benchmark.xmlrpc.latency; 28 29 import org.apache.xmlrpc.XmlRpcClient ; 31 import org.objectweb.benchmark.util.ResultPrinter; 32 33 34 41 public class Client 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 port; 63 64 65 private String host; 66 67 68 private XmlRpcClient ping_impl = null; 69 70 76 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"); 91 properties.load(propStream); 92 93 nb_step = Integer.parseInt( properties.getProperty("step.number") ); 94 nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") ); 95 step_start = Integer.parseInt( properties.getProperty("step.start") ); 96 port = "2000"; 97 host = properties.getProperty("com.host"); 98 } catch (Exception e) { 99 e.printStackTrace(); 100 } 101 } 102 103 109 115 120 public static void main(String [] args) 121 { 122 if (args.length != 1) 123 { 124 System.out.println("Usage: Client <dest_file>"); 125 System.exit(0); 126 } 127 128 Client c = new Client(args[0]); 129 c.run(); 130 } 131 132 135 public void run() 136 { 137 try{ 139 ping_impl = new XmlRpcClient ("http://"+host+":"+port); 140 }catch(Exception ex){ 141 ex.printStackTrace(); 142 } 143 144 test(); 146 } 147 148 151 public void test() 152 { 153 java.util.Vector args = new java.util.Vector (); 154 155 try 157 { 158 for (int i=0; i<step_start; i++) 159 ping_impl.execute ("pingServer.ping", args) ; 160 } catch (Exception e) { 161 e.printStackTrace(); 162 } 163 164 System.out.println("Running WS Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls."); 166 try{ 167 for(int j=0; j<nb_step; j++) 168 { 169 long timer = System.currentTimeMillis(); 170 171 for (int i=0; i<nb_step_invocation; i++) 172 ping_impl.execute ("pingServer.ping", args) ; 173 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation ); 174 175 ResultPrinter p = new ResultPrinter(result_file); 177 p.write(timer); 178 p.close(); 179 } 180 }catch(Exception ex){ 181 ex.printStackTrace(); 182 } 183 } 184 } 185 186 | Popular Tags |