KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > Start


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/Start.java,v 1.13.2.1 2004/09/18 20:03:13 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.swing.JOptionPane JavaDoc;
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 /**
40  * @author Michael Stover
41  * Created March 1, 2001
42  * @version $Revision: 1.13.2.1 $ Last updated: $Date: 2004/09/18 20:03:13 $
43  */

44 public class Start extends AbstractAction
45 {
46     private static Logger log = LoggingManager.getLoggerForClass();
47     
48
49     private static Set JavaDoc commands = new HashSet JavaDoc();
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     /**
59      * Constructor for the Start object.
60      */

61     public Start()
62     {
63     }
64
65     /**
66      * Gets the ActionNames attribute of the Start object.
67      *
68      *@return the ActionNames value
69      */

70     public Set JavaDoc getActionNames()
71     {
72         return commands;
73     }
74
75     public void doAction(ActionEvent JavaDoc 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