001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jmeter.visualizers;
018:
019: import java.awt.BorderLayout;
020: import java.awt.Component;
021: import java.awt.Dimension;
022: import javax.swing.BoxLayout;
023: import javax.swing.ImageIcon;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026:
027: import java.util.HashMap;
028:
029: import javax.swing.JScrollPane;
030:
031: import org.apache.jmeter.util.JMeterUtils;
032: import org.apache.jmeter.samplers.Clearable;
033:
034: /**
035: * The health panel is responsible for showing the health of the servers. It
036: * only uses the most current information to show the status.
037: */
038: public class MonitorHealthPanel extends JPanel implements
039: MonitorListener, Clearable {
040: private HashMap SERVERMAP = new HashMap();
041:
042: private JPanel SERVERS = null;
043:
044: private MonitorAccumModel MODEL;
045:
046: private JScrollPane SCROLL = null;
047:
048: // NOTUSED Font plainText = new Font("plain", Font.PLAIN, 9);
049: public static final String INFO_H = JMeterUtils
050: .getResString("monitor_equation_healthy"); //$NON-NLS-1$
051:
052: public static final String INFO_A = JMeterUtils
053: .getResString("monitor_equation_active"); //$NON-NLS-1$
054:
055: public static final String INFO_W = JMeterUtils
056: .getResString("monitor_equation_warning"); //$NON-NLS-1$
057:
058: public static final String INFO_D = JMeterUtils
059: .getResString("monitor_equation_dead"); //$NON-NLS-1$
060:
061: public static final String INFO_LOAD = JMeterUtils
062: .getResString("monitor_equation_load"); //$NON-NLS-1$
063:
064: /**
065: *
066: * @deprecated Only for use in unit testing
067: */
068: public MonitorHealthPanel() {
069: // log.warn("Only for use in unit testing");
070: }
071:
072: /**
073: *
074: */
075: public MonitorHealthPanel(MonitorAccumModel model) {
076: this .MODEL = model;
077: this .MODEL.addListener(this );
078: init();
079: }
080:
081: /**
082: * init is responsible for creating the necessary legends and information
083: * for the health panel.
084: */
085: protected void init() {
086: this .setLayout(new BorderLayout());
087: ImageIcon legend = JMeterUtils.getImage("monitor-legend.gif"); //$NON-NLS-1$
088: JLabel label = new JLabel(legend);
089: label.setPreferredSize(new Dimension(550, 25));
090: this .add(label, BorderLayout.NORTH);
091:
092: this .SERVERS = new JPanel();
093: this .SERVERS
094: .setLayout(new BoxLayout(SERVERS, BoxLayout.Y_AXIS));
095: this .SERVERS.setAlignmentX(Component.LEFT_ALIGNMENT);
096:
097: SCROLL = new JScrollPane(this .SERVERS);
098: SCROLL.setPreferredSize(new Dimension(300, 300));
099: this .add(SCROLL, BorderLayout.CENTER);
100:
101: // the equations
102: String eqstring1 = " " + INFO_H + " | " + INFO_A;
103: String eqstring2 = " " + INFO_W + " | " + INFO_D;
104: String eqstring3 = " " + INFO_LOAD;
105: JLabel eqs = new JLabel();
106: eqs.setLayout(new BorderLayout());
107: eqs.setPreferredSize(new Dimension(500, 60));
108: eqs.add(new JLabel(eqstring1), BorderLayout.NORTH);
109: eqs.add(new JLabel(eqstring2), BorderLayout.CENTER);
110: eqs.add(new JLabel(eqstring3), BorderLayout.SOUTH);
111: this .add(eqs, BorderLayout.SOUTH);
112: }
113:
114: /**
115: *
116: * @param model
117: */
118: public void addSample(MonitorModel model) {
119: if (SERVERMAP.containsKey(model.getURL())) {
120: ServerPanel pane = null;
121: if (SERVERMAP.get(model.getURL()) != null) {
122: pane = (ServerPanel) SERVERMAP.get((model.getURL()));
123: } else {
124: pane = new ServerPanel(model);
125: SERVERMAP.put(model.getURL(), pane);
126: }
127: pane.updateGui(model);
128: } else {
129: ServerPanel newpane = new ServerPanel(model);
130: SERVERMAP.put(model.getURL(), newpane);
131: this .SERVERS.add(newpane);
132: newpane.updateGui(model);
133: }
134: this .SERVERS.updateUI();
135: }
136:
137: /**
138: * clear will clear the hashmap, remove all ServerPanels from the servers
139: * pane, and update the ui.
140: */
141: public void clearData() {
142: this.SERVERMAP.clear();
143: this.SERVERS.removeAll();
144: this.SERVERS.updateUI();
145: }
146: }
|