1 18 19 package org.apache.jmeter.engine; 20 import java.net.MalformedURLException ; 21 import java.rmi.Naming ; 22 import java.rmi.NotBoundException ; 23 import java.rmi.RemoteException ; 24 25 import org.apache.jmeter.testelement.TestListener; 26 import org.apache.jorphan.collections.HashTree; 27 import org.apache.jorphan.collections.SearchByClass; 28 import org.apache.jorphan.logging.LoggingManager; 29 import org.apache.log.Logger; 30 31 32 36 public class ClientJMeterEngine implements JMeterEngine,Runnable 37 { 38 transient private static Logger log = LoggingManager.getLoggerForClass(); 39 RemoteJMeterEngine remote; 40 HashTree test; 41 SearchByClass testListeners; 42 ConvertListeners sampleListeners; 43 private String host; 44 45 public ClientJMeterEngine(String host) 46 throws MalformedURLException , NotBoundException , RemoteException 47 { 48 this((RemoteJMeterEngine) Naming.lookup("//" + host + "/JMeterEngine")); 49 this.host = host; 50 } 51 52 public ClientJMeterEngine(RemoteJMeterEngine remote) 53 { 54 this.remote = remote; 55 } 56 57 protected HashTree getTestTree() 58 { 59 return test; 60 } 61 62 public void configure(HashTree testTree) 63 { 64 test = testTree; 65 } 66 67 public void setHost(String host) 68 { 69 this.host = host; 70 } 71 72 public void runTest() 73 { 74 log.info("about to run remote test"); 75 new Thread (this).start(); 76 log.info("done initiating run command"); 77 } 78 79 public void stopTest() 80 { 81 try 82 { 83 remote.stopTest(); 84 } 85 catch (Exception ex) 86 { 87 log.error("", ex); 88 } 89 } 90 91 public void reset() 92 { 93 try 94 { 95 remote.reset(); 96 } 97 catch (Exception ex) 98 { 99 log.error("", ex); 100 } 101 } 102 103 106 public void run() 107 { 108 log.info("running clientengine run method"); 109 testListeners = new SearchByClass(TestListener.class); 110 getTestTree().traverse(testListeners); 111 sampleListeners = new ConvertListeners(); 112 113 try { 115 getTestTree().traverse(sampleListeners); 116 } 117 catch(IndexOutOfBoundsException e) 118 { 119 log.warn("Error replacing sample listeners",e); 120 } 121 122 try 123 { 124 remote.setHost(host); 125 log.info("sent host ="+host); 126 remote.configure(test); 127 log.info("sent test"); 128 remote.runTest(); 129 log.info("sent run command"); 130 } 131 catch(Exception ex) 132 { 133 log.error("",ex); 134 } 135 } 136 137 140 public void exit() 141 { 142 try 143 { 144 remote.exit(); 145 } 146 catch (RemoteException e) 147 { 148 log.warn("Could not perform remote exit: "+e.toString()); 149 } 150 } 151 } 152 | Popular Tags |