1 package org.apache.jmeter.module; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.Collection ; 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 script = FileUtil.toFile(c.getPrimaryFile()); 22 final String path = script.getCanonicalPath(); 24 25 EngineManager manager = Lookup.getDefault().lookup(EngineManager.class); 26 Collection <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 e) { 33 e.printStackTrace(); 34 } 35 } 36 37 protected int mode() { 38 return CookieAction.MODE_EXACTLY_ONE; 39 } 40 41 public String getName() { 42 return NbBundle.getMessage(JMeterRunAction.class, "CTL_JMeterRunAction"); 43 } 44 45 protected Class [] cookieClasses() { 46 return new Class [] { 47 DataObject.class 48 }; 49 } 50 51 protected void initialize() { 52 super.initialize(); 53 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 75 if (c == null || c.getPrimaryFile() == null) return false; 76 77 try { 78 File script = FileUtil.toFile(c.getPrimaryFile()); 79 final String path = script.getCanonicalPath(); 81 82 EngineManager manager = Lookup.getDefault().lookup(EngineManager.class); 83 Collection <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 ex) {} 88 89 return retValue; 90 } 91 92 protected boolean asynchronous() { 93 return false; 94 } 95 96 97 } 98 99 | Popular Tags |