KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/monitor/components/org/apache/jmeter/visualizers/MonitorModel.java,v 1.4 2004/03/20 22:10:02 sebb 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.io.Serializable JavaDoc;
20
21 import org.apache.jmeter.samplers.Clearable;
22
23 import java.text.SimpleDateFormat JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.List JavaDoc;
27
28 public class MonitorModel implements Clearable, Serializable JavaDoc, Cloneable JavaDoc
29 {
30
31     //private String name;
32
private List JavaDoc listeners;
33     private MonitorStats current =
34         new MonitorStats(0,0,0,0,0,"","","",System.currentTimeMillis());
35     
36     /**
37      *
38      */

39     public MonitorModel()
40     {
41         super();
42         listeners = new LinkedList JavaDoc();
43     }
44
45     public MonitorModel(MonitorStats stat){
46         this.current = stat;
47     }
48     public void setName(String JavaDoc name){
49         //this.name = name;
50
}
51     
52     public String JavaDoc getName(){
53         return this.getURL();
54     }
55     
56     public int getHealth(){
57         return this.current.health;
58     }
59     
60     public int getLoad(){
61         return this.current.load;
62     }
63
64     public int getCpuload(){
65         return this.current.cpuload;
66     }
67     
68     public int getMemload(){
69         return this.current.memload;
70     }
71     
72     public int getThreadload(){
73         return this.current.threadload;
74     }
75     
76     public String JavaDoc getHost(){
77         return this.current.host;
78     }
79     
80     public String JavaDoc getPort(){
81         return this.current.port;
82     }
83     
84     public String JavaDoc getProtocol(){
85         return this.current.protocol;
86     }
87     
88     public long getTimestamp(){
89         return this.current.timestamp;
90     }
91     
92     public String JavaDoc getURL(){
93         return this.current.getURL();
94     }
95     
96     /**
97      * Method will return a formatted date using
98      * SimpleDateFormat.
99      * @return String
100      */

101     public String JavaDoc getTimestampString(){
102         Date JavaDoc date = new Date JavaDoc(this.current.timestamp);
103         SimpleDateFormat JavaDoc ft = new SimpleDateFormat JavaDoc();
104         return ft.format(date);
105     }
106     
107     /**
108      * Method is used by DefaultMutableTreeNode to get
109      * the label for the node.
110      */

111     public String JavaDoc toString(){
112         return getURL();
113     }
114
115     /**
116      * clear will create a new MonitorStats object.
117      */

118     public void clear()
119     {
120         current =
121             new MonitorStats(0,0,0,0,0,"","","",System.currentTimeMillis());
122     }
123
124     /**
125      * notify the listeners with the MonitorModel object.
126      * @param model
127      */

128     public void notifyListeners(MonitorModel model)
129     {
130         for (int idx=0; idx < listeners.size(); idx++){
131             MonitorListener ml = (MonitorListener)listeners.get(idx);
132             ml.addSample(model);
133         }
134     }
135     
136     public void addListener(MonitorListener listener){
137         listeners.add(listener);
138     }
139     
140     /**
141      * a clone method is provided for convienance. In some
142      * cases, it may be desirable to clone the object.
143      */

144     public Object JavaDoc clone(){
145         MonitorStats newstats =
146             new MonitorStats(current.health,
147                 current.load,
148                 current.cpuload,
149                 current.memload,
150                 current.threadload,
151                 current.host,
152                 current.port,
153                 current.protocol,
154                 current.timestamp);
155         return new MonitorModel(newstats);
156     }
157 }
158
Popular Tags