1 18 19 package org.apache.jmeter.gui.action; 20 21 import java.awt.event.ActionEvent ; 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import javax.swing.JOptionPane ; 26 27 import org.apache.jmeter.engine.JMeterEngineException; 28 import org.apache.jmeter.engine.StandardJMeterEngine; 29 import org.apache.jmeter.engine.TreeCloner; 30 import org.apache.jmeter.engine.util.DisabledComponentRemover; 31 import org.apache.jmeter.gui.GuiPackage; 32 import org.apache.jmeter.gui.util.JMeterMenuBar; 33 import org.apache.jmeter.testelement.TestPlan; 34 import org.apache.jmeter.util.JMeterUtils; 35 import org.apache.jorphan.collections.HashTree; 36 import org.apache.jorphan.logging.LoggingManager; 37 import org.apache.log.Logger; 38 39 44 public class Start extends AbstractAction 45 { 46 private static Logger log = LoggingManager.getLoggerForClass(); 47 48 49 private static Set commands = new HashSet (); 50 static { 51 commands.add(JMeterMenuBar.ACTION_START); 52 commands.add(JMeterMenuBar.ACTION_STOP); 53 commands.add(JMeterMenuBar.ACTION_SHUTDOWN); 54 } 55 56 private StandardJMeterEngine engine; 57 58 61 public Start() 62 { 63 } 64 65 70 public Set getActionNames() 71 { 72 return commands; 73 } 74 75 public void doAction(ActionEvent e) 76 { 77 if (e.getActionCommand().equals(JMeterMenuBar.ACTION_START)) 78 { 79 startEngine(); 80 } 81 else if (e.getActionCommand().equals(JMeterMenuBar.ACTION_STOP)) 82 { 83 if (engine != null) 84 { 85 GuiPackage.getInstance().getMainFrame().showStoppingMessage(""); 86 engine.stopTest(); 87 engine = null; 88 } 89 } 90 else if (e.getActionCommand().equals(JMeterMenuBar.ACTION_SHUTDOWN)) 91 { 92 if (engine != null) 93 { 94 GuiPackage.getInstance().getMainFrame().showStoppingMessage(""); 95 engine.askThreadsToStop(); 96 engine = null; 97 } 98 } 99 } 100 101 protected void startEngine() 102 { 103 GuiPackage gui = GuiPackage.getInstance(); 104 engine = new StandardJMeterEngine(); 105 HashTree testTree = gui.getTreeModel().getTestPlan(); 106 convertSubTree(testTree); 107 DisabledComponentRemover remover = 108 new DisabledComponentRemover(testTree); 109 testTree.traverse(remover); 110 testTree.add(testTree.getArray()[0], gui.getMainFrame()); 111 log.debug( 112 "test plan before cloning is running version: " 113 + ((TestPlan) testTree.getArray()[0]).isRunningVersion()); 114 TreeCloner cloner = new TreeCloner(false); 115 testTree.traverse(cloner); 116 engine.configure(cloner.getClonedTree()); 117 try 118 { 119 engine.runTest(); 120 } 121 catch (JMeterEngineException e) 122 { 123 JOptionPane.showMessageDialog( 124 gui.getMainFrame(), 125 e.getMessage(), 126 JMeterUtils.getResString("Error Occurred"), 127 JOptionPane.ERROR_MESSAGE); 128 } 129 log.debug( 130 "test plan after cloning and running test is running version: " 131 + ((TestPlan) testTree.getArray()[0]).isRunningVersion()); 132 } 133 } 134 | Popular Tags |