1 26 27 28 package org.objectweb.benchmark.fractal.latency; 29 30 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.BindingController; 33 import org.objectweb.fractal.api.control.IllegalBindingException; 34 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 35 36 import org.objectweb.benchmark.util.ResultPrinter; 37 38 39 46 public class Client 47 implements BindingController, 48 Runnable 49 { 50 51 57 58 private int nb_step; 59 60 61 private int nb_step_invocation; 62 63 64 private int step_start; 65 66 67 private String result_file; 68 69 70 private String host; 71 72 73 private PingItf ping_impl; 74 75 81 84 public Client() 85 { 86 java.util.Properties properties = new java.util.Properties (); 87 88 try { 89 java.io.InputStream propStream = null; 90 91 propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties"); 93 properties.load(propStream); 94 95 nb_step = Integer.parseInt( properties.getProperty("step.number") ); 96 nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") ); 97 step_start = Integer.parseInt( properties.getProperty("step.start") ); 98 host = properties.getProperty("com.host"); 99 100 propStream = getClass().getClassLoader().getResourceAsStream("build.properties"); 102 properties.load(propStream); 103 result_file = properties.getProperty("dest.file"); 104 } catch (Exception e) { 105 e.printStackTrace(); 106 } 107 } 108 109 115 118 public void test() 119 { 120 for (int i=0; i<step_start; i++) 122 ping_impl.ping(); 123 124 System.out.println( "Running Fractal Rmi Benchmark with " + nb_step + " step(s) of " 126 + nb_step_invocation +" method calls." ); 127 try{ 128 for(int j=0; j<nb_step; j++) 129 { 130 long timer = System.currentTimeMillis(); 131 132 for (int i=0; i<nb_step_invocation; i++) 133 ping_impl.ping(); 134 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation ); 135 136 ResultPrinter p = new ResultPrinter(result_file); 138 p.write(timer); 139 p.close(); 140 } 141 }catch(Exception ex){ 142 ex.printStackTrace(); 143 } 144 } 145 146 149 public String [] listFc() 150 { 151 String [] list = new String [0]; 152 153 if (ping_impl != null) 154 { 155 list = new String [1]; 156 list[0] = "PingItf"; 157 } 158 159 return list; 160 } 161 162 165 public Object lookupFc(final String cItf) 166 throws NoSuchInterfaceException 167 { 168 if (cItf.compareTo("PingItf") == 0) 169 { 170 return ping_impl; 171 } 172 throw new NoSuchInterfaceException(cItf); 173 } 174 175 178 public void bindFc(final String cItf, final Object sItf) 179 throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException 180 { 181 if (cItf.compareTo("PingItf") == 0) 182 { 183 ping_impl = (PingItf) sItf; 184 } 185 else 186 throw new NoSuchInterfaceException(cItf); 187 } 188 189 192 public void unbindFc(final String cItf) 193 throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException 194 { 195 if (cItf.compareTo("PingItf") == 0) 196 { 197 ping_impl = null; 198 } 199 else 200 throw new NoSuchInterfaceException(cItf); 201 } 202 203 206 public void run() 207 { 208 test(); 209 } 210 } 211 | Popular Tags |