KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/components/org/apache/jmeter/visualizers/MonitorHealthPanel.java,v 1.4 2004/03/16 13:56:34 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.Component JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.Font JavaDoc;
23 import javax.swing.BoxLayout JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27
28 import java.util.HashMap JavaDoc;
29
30 import javax.swing.JScrollPane JavaDoc;
31
32 import org.apache.jmeter.util.JMeterUtils;
33 import org.apache.jmeter.samplers.Clearable;
34 /**
35  * The health panel is responsible for showing the health
36  * of the servers. It only uses the most current information
37  * to show the status.
38  */

39 public class MonitorHealthPanel extends JPanel JavaDoc
40     implements MonitorListener, Clearable
41 {
42     private HashMap JavaDoc SERVERMAP = new HashMap JavaDoc();
43     private JPanel JavaDoc SERVERS = null;
44     private MonitorAccumModel MODEL;
45     private JScrollPane JavaDoc SCROLL = null;
46     
47     Font JavaDoc plainText = new Font JavaDoc("plain", Font.PLAIN, 9);
48     public static final String JavaDoc INFO_H =
49         JMeterUtils.getResString("monitor_equation_healthy");
50     public static final String JavaDoc INFO_A =
51         JMeterUtils.getResString("monitor_equation_active");
52     public static final String JavaDoc INFO_W =
53         JMeterUtils.getResString("monitor_equation_warning");
54     public static final String JavaDoc INFO_D =
55         JMeterUtils.getResString("monitor_equation_dead");
56     public static final String JavaDoc INFO_LOAD =
57         JMeterUtils.getResString("monitor_equation_load");
58
59     /**
60      *
61      * @deprecated Only for use in unit testing
62      */

63     public MonitorHealthPanel()
64     {
65         //log.warn("Only for use in unit testing");
66
}
67
68     /**
69      *
70      */

71     public MonitorHealthPanel(MonitorAccumModel model)
72     {
73         this.MODEL = model;
74         this.MODEL.addListener(this);
75         init();
76     }
77
78     /**
79      * init is responsible for creating the necessary legends
80      * and information for the health panel.
81      */

82     protected void init(){
83         this.setLayout(new BorderLayout JavaDoc());
84         ImageIcon JavaDoc legend = JMeterUtils.getImage("monitor-legend.gif");
85         JLabel JavaDoc label = new JLabel JavaDoc(legend);
86         label.setPreferredSize(new Dimension JavaDoc(550,25));
87         this.add(label,BorderLayout.NORTH);
88
89         this.SERVERS = new JPanel JavaDoc();
90         this.SERVERS.setLayout(new BoxLayout JavaDoc(SERVERS, BoxLayout.Y_AXIS));
91         this.SERVERS.setAlignmentX(Component.LEFT_ALIGNMENT);
92
93         SCROLL = new JScrollPane JavaDoc(this.SERVERS);
94         SCROLL.setPreferredSize(new Dimension JavaDoc(300,300));
95         this.add(SCROLL,BorderLayout.CENTER);
96         
97         // the equations
98
String JavaDoc eqstring1 = " " + INFO_H + " | " + INFO_A;
99         String JavaDoc eqstring2 = " " + INFO_W + " | " + INFO_D;
100         String JavaDoc eqstring3 = " " + INFO_LOAD;
101         JLabel JavaDoc eqs = new JLabel JavaDoc();
102         eqs.setLayout(new BorderLayout JavaDoc());
103         eqs.setPreferredSize(new Dimension JavaDoc(500,60));
104         eqs.add(new JLabel JavaDoc(eqstring1),BorderLayout.NORTH);
105         eqs.add(new JLabel JavaDoc(eqstring2),BorderLayout.CENTER);
106         eqs.add(new JLabel JavaDoc(eqstring3),BorderLayout.SOUTH);
107         this.add(eqs,BorderLayout.SOUTH);
108     }
109
110     /**
111      *
112      * @param model
113      */

114     public void addSample(MonitorModel model){
115         if (SERVERMAP.containsKey(model.getURL())){
116             ServerPanel pane = null;
117             if(SERVERMAP.get(model.getURL()) != null){
118                 pane = (ServerPanel)SERVERMAP.get((model.getURL()));
119             } else {
120                 pane = new ServerPanel(model);
121                 SERVERMAP.put(model.getURL(),pane);
122             }
123             pane.updateGui(model);
124         } else {
125             ServerPanel newpane = new ServerPanel(model);
126             SERVERMAP.put(model.getURL(),newpane);
127             this.SERVERS.add(newpane);
128             newpane.updateGui(model);
129         }
130         this.SERVERS.updateUI();
131     }
132
133     /**
134      * clear will clear the hashmap, remove all ServerPanels
135      * from the servers pane, and update the ui.
136      */

137     public void clear(){
138         this.SERVERMAP.clear();
139         this.SERVERS.removeAll();
140         this.SERVERS.updateUI();
141     }
142 }
143
Popular Tags