1 26 27 package org.objectweb.benchmark.ejb.latency; 28 29 import java.rmi.RemoteException ; 31 32 import javax.naming.InitialContext ; 33 import javax.rmi.PortableRemoteObject ; 34 import org.objectweb.benchmark.util.ResultPrinter; 35 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 PingRemoteInterface pingBean = null; 66 67 73 79 public Client(String name) 80 { 81 result_file = name; 82 java.util.Properties properties = new java.util.Properties (); 83 84 85 try { 86 java.io.InputStream propStream = null; 87 88 propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties"); 89 properties.load(propStream); 90 91 nb_step = Integer.parseInt( properties.getProperty("step.number") ); 92 nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") ); 93 step_start = Integer.parseInt( properties.getProperty("step.start") ); 94 }catch (Exception e) { 95 e.printStackTrace(); 96 } 97 98 } 99 100 106 112 117 public static void main(String [] args) 118 throws RemoteException 119 { 120 if (args.length != 1) 121 { 122 System.out.println("Usage: Client <dest_file>"); 123 System.exit(0); 124 } 125 126 Client c = new Client(args[0]); 127 c.run(); 128 } 129 130 133 public void run() 134 throws RemoteException 135 { 136 PingRemoteHome pingHome = null; 137 138 try { 140 InitialContext ctx = new InitialContext () ; 141 Object obj= ctx.lookup("MyPingBean") ; 142 143 pingHome = (PingRemoteHome) PortableRemoteObject.narrow(obj, PingRemoteHome.class) ; 144 pingBean = pingHome.create() ; 145 }catch(Exception ex){ 146 ex.printStackTrace(); 147 } 148 149 test(); 151 } 152 153 156 public void test() 157 throws RemoteException 158 { 159 for (int i=0; i<step_start; i++) 161 pingBean.ping(); 162 163 System.out.println("Running EJB Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls."); 165 try{ 166 for(int j=0; j<nb_step; j++) 167 { 168 long timer = System.currentTimeMillis(); 169 for (int i=0; i<nb_step_invocation; i++) 170 pingBean.ping(); 171 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation ); 172 173 ResultPrinter p = new ResultPrinter(result_file); 175 p.write(timer); 176 p.close(); 177 } 178 }catch(Exception ex){ 179 ex.printStackTrace(); 180 } 181 } 182 } 183 | Popular Tags |