KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > module > JMeterRunAction


1 package org.apache.jmeter.module;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.Collection JavaDoc;
6 import org.netbeans.modules.loadgenerator.api.EngineManager;
7 import org.netbeans.modules.loadgenerator.spi.Engine;
8 import org.openide.filesystems.FileUtil;
9 import org.openide.loaders.DataObject;
10 import org.openide.nodes.Node;
11 import org.openide.util.HelpCtx;
12 import org.openide.util.Lookup;
13 import org.openide.util.NbBundle;
14 import org.openide.util.actions.CookieAction;
15
16 public final class JMeterRunAction extends CookieAction {
17   
18   protected void performAction(Node[] activatedNodes) {
19     DataObject c = (DataObject) activatedNodes[0].getCookie(DataObject.class);
20     try {
21       File JavaDoc script = FileUtil.toFile(c.getPrimaryFile());
22 // JMeterIntegrationEngine.getDefault().runTestPlan(script.getCanonicalPath());
23
final String JavaDoc path = script.getCanonicalPath();
24       
25       EngineManager manager = Lookup.getDefault().lookup(EngineManager.class);
26       Collection JavaDoc<Engine> loadgens = manager.findEngines(FileUtil.getExtension(path));
27       if (loadgens.size() == 1) {
28         Engine provider = loadgens.iterator().next();
29         
30         manager.startProcess(provider.createProcess(path));
31       }
32     } catch (Exception JavaDoc e) {
33       e.printStackTrace();
34     }
35   }
36   
37   protected int mode() {
38     return CookieAction.MODE_EXACTLY_ONE;
39   }
40   
41   public String JavaDoc getName() {
42     return NbBundle.getMessage(JMeterRunAction.class, "CTL_JMeterRunAction");
43   }
44   
45   protected Class JavaDoc[] cookieClasses() {
46     return new Class JavaDoc[] {
47       DataObject.class
48     };
49   }
50   
51   protected void initialize() {
52     super.initialize();
53     // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
54
putValue("noIconInMenu", Boolean.TRUE);
55   }
56   
57   public HelpCtx getHelpCtx() {
58     return HelpCtx.DEFAULT_HELP;
59   }
60
61   protected boolean enable(Node[] node) {
62     boolean retValue;
63     if (node.length < 1)
64       return false;
65     
66     retValue = super.enable(node);
67     if (node == null || node[0] == null)
68       return retValue;
69     
70     DataObject c = (DataObject) node[0].getCookie(DataObject.class);
71     
72     /* according to http://www.netbeans.org/issues/show_bug.cgi?id=94823
73      * using "c" without checking for NULL causes NPE randomly; this check should prevent NPE
74      */

75     if (c == null || c.getPrimaryFile() == null) return false;
76     
77     try {
78       File JavaDoc script = FileUtil.toFile(c.getPrimaryFile());
79 // JMeterIntegrationEngine.getDefault().runTestPlan(script.getCanonicalPath());
80
final String JavaDoc path = script.getCanonicalPath();
81       
82       EngineManager manager = Lookup.getDefault().lookup(EngineManager.class);
83       Collection JavaDoc<Engine> loadgens = manager.findEngines(FileUtil.getExtension(path));
84       for(Engine provider : loadgens) {
85         retValue = retValue && provider.isReady() && (provider.getProcessByName(path) == null || !provider.getProcessByName(path).isRunning()) ;
86       }
87     } catch (IOException JavaDoc ex) {}
88     
89     return retValue;
90   }
91
92   protected boolean asynchronous() {
93     return false;
94   }
95   
96   
97 }
98
99
Popular Tags