001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.action;
020:
021: import java.awt.event.ActionEvent;
022: import java.util.HashSet;
023: import java.util.Set;
024:
025: import javax.swing.JOptionPane;
026:
027: import org.apache.jmeter.JMeter;
028: import org.apache.jmeter.engine.JMeterEngineException;
029: import org.apache.jmeter.engine.StandardJMeterEngine;
030: import org.apache.jmeter.engine.TreeCloner;
031: import org.apache.jmeter.engine.util.DisabledComponentRemover;
032: import org.apache.jmeter.gui.GuiPackage;
033: import org.apache.jmeter.testelement.TestPlan;
034: import org.apache.jmeter.util.JMeterUtils;
035: import org.apache.jorphan.collections.HashTree;
036: import org.apache.jorphan.logging.LoggingManager;
037: import org.apache.log.Logger;
038:
039: public class Start extends AbstractAction {
040: private static Logger log = LoggingManager.getLoggerForClass();
041:
042: private static Set commands = new HashSet();
043: static {
044: commands.add(ActionNames.ACTION_START);
045: commands.add(ActionNames.ACTION_STOP);
046: commands.add(ActionNames.ACTION_SHUTDOWN);
047: }
048:
049: private StandardJMeterEngine engine;
050:
051: /**
052: * Constructor for the Start object.
053: */
054: public Start() {
055: }
056:
057: /**
058: * Gets the ActionNames attribute of the Start object.
059: *
060: * @return the ActionNames value
061: */
062: public Set getActionNames() {
063: return commands;
064: }
065:
066: public void doAction(ActionEvent e) {
067: if (e.getActionCommand().equals(ActionNames.ACTION_START)) {
068: popupShouldSave(e);
069: startEngine();
070: } else if (e.getActionCommand().equals(ActionNames.ACTION_STOP)) {
071: if (engine != null) {
072: GuiPackage.getInstance().getMainFrame()
073: .showStoppingMessage("");
074: engine.stopTest();
075: engine = null;
076: }
077: } else if (e.getActionCommand().equals(
078: ActionNames.ACTION_SHUTDOWN)) {
079: if (engine != null) {
080: GuiPackage.getInstance().getMainFrame()
081: .showStoppingMessage("");
082: engine.askThreadsToStop();
083: engine = null;
084: }
085: }
086: }
087:
088: protected void startEngine() {
089: GuiPackage gui = GuiPackage.getInstance();
090: engine = new StandardJMeterEngine();
091: HashTree testTree = gui.getTreeModel().getTestPlan();
092: JMeter.convertSubTree(testTree);
093: DisabledComponentRemover remover = new DisabledComponentRemover(
094: testTree);
095: testTree.traverse(remover);
096: testTree.add(testTree.getArray()[0], gui.getMainFrame());
097: log.debug("test plan before cloning is running version: "
098: + ((TestPlan) testTree.getArray()[0])
099: .isRunningVersion());
100: TreeCloner cloner = new TreeCloner(false);
101: testTree.traverse(cloner);
102: engine.configure(cloner.getClonedTree());
103: try {
104: engine.runTest();
105: } catch (JMeterEngineException e) {
106: JOptionPane.showMessageDialog(gui.getMainFrame(), e
107: .getMessage(), JMeterUtils
108: .getResString("Error Occurred"),
109: JOptionPane.ERROR_MESSAGE);
110: }
111: log
112: .debug("test plan after cloning and running test is running version: "
113: + ((TestPlan) testTree.getArray()[0])
114: .isRunningVersion());
115: }
116: }
|