KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > module > nodes > RuntimeNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.jmeter.module.nodes;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import org.apache.jmeter.module.actions.ProcessesCleanupAction;
26 import org.apache.jmeter.module.integration.JMeterIntegrationEngine;
27 import org.apache.jmeter.module.loadgenerator.spi.impl.ProcessDescriptor;
28 import org.openide.nodes.AbstractNode;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.util.Lookup;
32
33 /**
34  *
35  * @author Jaroslav Bachorik
36  */

37 public class RuntimeNode extends AbstractNode {
38   private static class RuntimeChildren extends Children.Array {
39     public Node findChild(String JavaDoc string) {
40       Node retValue;
41       
42       retValue = super.findChild(string);
43       return retValue;
44     }
45     
46     public Node[] getNodes(boolean b) {
47       if (b) {
48         Node[] nodes = super.getNodes(b);
49         remove(nodes);
50         processNodes();
51       }
52       return super.getNodes(b);
53     }
54     
55     private void processNodes() {
56       Collection JavaDoc<Node> nodes = new ArrayList JavaDoc<Node>();
57       try {
58         for(ProcessDescriptor process : JMeterIntegrationEngine.getDefault().getProcesses() ) {
59           final String JavaDoc processName = process.getScriptPath();
60           final String JavaDoc displayName = process.getDisplayName();
61           final boolean running = process.isRunning();
62           
63           nodes.add(new ProcessNode(process) {
64             public String JavaDoc getDisplayName() {
65               return displayName + " " + (running ? "(running)" : "(finished)");
66             }
67             
68             public String JavaDoc getName() {
69               return processName;
70             }
71           });
72         }
73       } catch (Exception JavaDoc e) {
74         e.printStackTrace();
75       }
76       add(nodes.toArray(new Node[]{}));
77     }
78   }
79   /** Creates a new instance of RuntimeNode */
80   public RuntimeNode(Children children) {
81     super(children);
82     setName("Load Generator");
83   }
84   
85   public RuntimeNode(Children children, Lookup lookup) {
86     super(children, lookup);
87     setName("Load Generator");
88   }
89   
90   public static RuntimeNode getInstance() {
91     Children chldrn = new RuntimeChildren();
92 // Node noProcessesNode = new AbstractNode(Children.LEAF);
93
// noProcessesNode.setName("JMeter: Test Plan (Finished)");
94
//
95
// Node aProcessNode = new AbstractNode(Children.LEAF);
96
// aProcessNode.setName("JMeter: Test Plan (Running)");
97
// chldrn.add(new Node[]{noProcessesNode, aProcessNode});
98
//
99
return new RuntimeNode(chldrn);
100   }
101
102   public Action JavaDoc[] getActions(boolean b) {
103     return new Action JavaDoc[]{ProcessesCleanupAction.findObject(ProcessesCleanupAction.class, true)};
104   }
105 }
106
Popular Tags