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.io.Serializable;
020:
021: import org.apache.jmeter.samplers.Clearable;
022:
023: import java.text.SimpleDateFormat;
024: import java.util.Date;
025: import java.util.LinkedList;
026: import java.util.List;
027:
028: public class MonitorModel implements Clearable, Serializable, Cloneable {
029:
030: // private String name;
031: private List listeners;
032:
033: private MonitorStats current = new MonitorStats(0, 0, 0, 0, 0, "",
034: "", "", System.currentTimeMillis());
035:
036: /**
037: *
038: */
039: public MonitorModel() {
040: super ();
041: listeners = new LinkedList();
042: }
043:
044: public MonitorModel(MonitorStats stat) {
045: this .current = stat;
046: }
047:
048: public void setName(String name) {
049: // this.name = name;
050: }
051:
052: public String getName() {
053: return this .getURL();
054: }
055:
056: public int getHealth() {
057: return this .current.getHealth();
058: }
059:
060: public int getLoad() {
061: return this .current.getLoad();
062: }
063:
064: public int getCpuload() {
065: return this .current.getCpuLoad();
066: }
067:
068: public int getMemload() {
069: return this .current.getMemLoad();
070: }
071:
072: public int getThreadload() {
073: return this .current.getThreadLoad();
074: }
075:
076: public String getHost() {
077: return this .current.getHost();
078: }
079:
080: public String getPort() {
081: return this .current.getPort();
082: }
083:
084: public String getProtocol() {
085: return this .current.getProtocol();
086: }
087:
088: public long getTimestamp() {
089: return this .current.getTimeStamp();
090: }
091:
092: public String getURL() {
093: return this .current.getURL();
094: }
095:
096: /**
097: * Method will return a formatted date using SimpleDateFormat.
098: *
099: * @return String
100: */
101: public String getTimestampString() {
102: Date date = new Date(this .current.getTimeStamp());
103: SimpleDateFormat ft = new SimpleDateFormat();
104: return ft.format(date);
105: }
106:
107: /**
108: * Method is used by DefaultMutableTreeNode to get the label for the node.
109: */
110: public String toString() {
111: return getURL();
112: }
113:
114: /**
115: * clear will create a new MonitorStats object.
116: */
117: public void clearData() {
118: current = new MonitorStats(0, 0, 0, 0, 0, "", "", "", System
119: .currentTimeMillis());
120: }
121:
122: /**
123: * notify the listeners with the MonitorModel object.
124: *
125: * @param model
126: */
127: public void notifyListeners(MonitorModel model) {
128: for (int idx = 0; idx < listeners.size(); idx++) {
129: MonitorListener ml = (MonitorListener) listeners.get(idx);
130: ml.addSample(model);
131: }
132: }
133:
134: public void addListener(MonitorListener listener) {
135: listeners.add(listener);
136: }
137:
138: /**
139: * a clone method is provided for convienance. In some cases, it may be
140: * desirable to clone the object.
141: */
142: public Object clone() {
143: return new MonitorModel(cloneMonitorStats());
144: }
145:
146: /**
147: * a clone method to clone the stats
148: *
149: * @return new instance of the class
150: */
151: public MonitorStats cloneMonitorStats() {
152: return new MonitorStats(current.getHealth(), current.getLoad(),
153: current.getCpuLoad(), current.getMemLoad(), current
154: .getThreadLoad(), current.getHost(), current
155: .getPort(), current.getProtocol(), current
156: .getTimeStamp());
157: }
158: }
|