KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > visualizers > MonitorHealthVisualizer


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/components/org/apache/jmeter/visualizers/MonitorHealthVisualizer.java,v 1.6 2004/03/18 03:02:08 woolfel Exp $
2
/*
3  * Copyright 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 package org.apache.jmeter.visualizers;
18
19 import java.awt.BorderLayout JavaDoc;
20 import java.awt.Container JavaDoc;
21 import java.awt.Graphics JavaDoc;
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import java.awt.Image JavaDoc;
25
26 import javax.swing.border.Border JavaDoc;
27 import javax.swing.border.EmptyBorder JavaDoc;
28
29 import org.apache.jmeter.gui.util.VerticalPanel;
30 import org.apache.jmeter.reporters.ResultCollector;
31 import org.apache.jmeter.testelement.TestElement;
32
33 import org.apache.jmeter.samplers.Clearable;
34 import org.apache.jmeter.samplers.SampleResult;
35 import org.apache.jmeter.util.JMeterUtils;
36 import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
37
38 /**
39  * For performance reasons, I am using tabs for the
40  * visualizers. Since a visualizer is heavy weight,
41  * I don not want to have two separate result
42  * collectors rather the same information. Instead,
43  * I would rather have the visualizer be the
44  * container for the data and simply pass the data
45  * to child JComponents. In the future, we may want
46  * to add email alerts as a third tab.
47  */

48 public class MonitorHealthVisualizer extends AbstractVisualizer
49     implements ImageVisualizer, ItemListener JavaDoc, GraphListener, Clearable
50 {
51     private MonitorTabPane TABPANE;
52     private MonitorHealthPanel HEALTHPANE;
53     private MonitorPerformancePanel PERFPANE;
54     private MonitorAccumModel MODEL;
55     private MonitorGraph GRAPH;
56     
57     public static final String JavaDoc BUFFER = "monitor.buffer.size";
58     
59     /**
60      * Constructor for the GraphVisualizer object.
61      */

62     public MonitorHealthVisualizer()
63     {
64         MODEL = new MonitorAccumModel();
65         GRAPH = new MonitorGraph(MODEL);
66         init();
67         MODEL.setBufferSize(JMeterUtils.getPropDefault(BUFFER,800));
68     }
69
70     public String JavaDoc getLabelResource()
71     {
72         return "monitor_health_title";
73     }
74
75     /**
76      * Because of the unique requirements of a monitor
77      * We have to handle the results differently than
78      * normal GUI components. A monitor should be able
79      * to run for a very long time without eating up
80      * all the memory.
81      */

82     public void add(SampleResult res)
83     {
84         MODEL.addSample(res);
85     }
86     
87     public Image JavaDoc getImage()
88     {
89         Image JavaDoc result = GRAPH.createImage(this.getWidth(),this.getHeight());
90         Graphics JavaDoc image = result.getGraphics();
91         GRAPH.paintComponent(image);
92         return result;
93     }
94
95     public void itemStateChanged(ItemEvent JavaDoc e)
96     {
97     }
98     
99     public synchronized void updateGui()
100     {
101         this.repaint();
102     }
103
104     public synchronized void updateGui(Sample s)
105     {
106         this.repaint();
107     }
108
109     /**
110      * Initialize the GUI.
111      */

112     private void init()
113     {
114         this.setLayout(new BorderLayout JavaDoc());
115
116         // MAIN PANEL
117
Border JavaDoc margin = new EmptyBorder JavaDoc(10, 10, 5, 10);
118         this.setBorder(margin);
119         
120         // Add the main panel and the graph
121
this.add(this.makeTitlePanel(), BorderLayout.NORTH);
122         this.createTabs();
123     }
124     
125     protected void createTabs(){
126         TABPANE = new MonitorTabPane();
127         createHealthPane(TABPANE);
128         createPerformancePane(TABPANE);
129         this.add(TABPANE, BorderLayout.CENTER);
130     }
131
132     /**
133      * Create the JPanel
134      * @param pane
135      */

136     public void createHealthPane(MonitorTabPane pane){
137         HEALTHPANE = new MonitorHealthPanel(MODEL);
138         pane.addTab(JMeterUtils.getResString("monitor_health_tab_title"),
139             HEALTHPANE);
140     }
141
142     /**
143      * Create the JSplitPane for the performance history
144      * @param pane
145      */

146     public void createPerformancePane(MonitorTabPane pane){
147         PERFPANE = new MonitorPerformancePanel(MODEL,GRAPH);
148         pane.addTab(JMeterUtils.getResString("monitor_performance_tab_title"),
149             PERFPANE);
150     }
151     
152     protected Container JavaDoc makeTitlePanel()
153     {
154         VerticalPanel titlePanel = new VerticalPanel();
155         titlePanel.add(createTitleLabel());
156         titlePanel.add(getNamePanel());
157         return titlePanel;
158     }
159
160     /**
161      * Clear will clear the MonitorAccumModel and create a
162      * new instance.
163      */

164     public void clear(){
165         this.MODEL.clear();
166         this.HEALTHPANE.clear();
167         this.PERFPANE.clear();
168     }
169     
170     public TestElement createTestElement()
171     {
172         if (collector == null)
173         {
174             collector = new ResultCollector();
175         }
176         modifyTestElement(collector);
177         return (TestElement) collector.clone();
178     }
179 }
180
Popular Tags